[Major] Removed the Query API, use Search API instead

This commit is contained in:
Robert von Burg 2021-09-05 12:46:45 +02:00
parent e726c8f931
commit 7ffaab1bb8
111 changed files with 57 additions and 7723 deletions

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 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.
@ -15,16 +15,11 @@
*/
package li.strolch.agent.api;
import java.util.List;
import li.strolch.model.activity.Activity;
import li.strolch.model.query.ActivityQuery;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ActivityMap extends ElementMap<Activity> {
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> query);
}

View File

@ -1,12 +1,12 @@
/*
* 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.
@ -19,7 +19,6 @@ import java.util.List;
import java.util.Set;
import li.strolch.model.audit.Audit;
import li.strolch.model.query.AuditQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.collections.DateRange;
@ -28,43 +27,41 @@ import li.strolch.utils.collections.DateRange;
*/
public interface AuditTrail {
public boolean isEnabled();
boolean isEnabled();
public boolean hasAudit(StrolchTransaction tx, String type, Long id);
boolean hasAudit(StrolchTransaction tx, String type, Long id);
public long querySize(StrolchTransaction tx, DateRange dateRange);
long querySize(StrolchTransaction tx, DateRange dateRange);
public long querySize(StrolchTransaction tx, String type, DateRange dateRange);
long querySize(StrolchTransaction tx, String type, DateRange dateRange);
public Set<String> getTypes(StrolchTransaction tx);
Set<String> getTypes(StrolchTransaction tx);
/**
* Retrieves the audit with the given id, or null if it does not exist
*
*
* @param tx
* the open transaction
* the open transaction
* @param id
* the id of the element to retrieve
*
* the id of the element to retrieve
*
* @return the element with the type and id, or null if it does not exist
*/
public Audit getBy(StrolchTransaction tx, String type, Long id);
Audit getBy(StrolchTransaction tx, String type, Long id);
public List<Audit> getAllElements(StrolchTransaction tx, String type, DateRange dateRange);
List<Audit> getAllElements(StrolchTransaction tx, String type, DateRange dateRange);
public void add(StrolchTransaction tx, Audit audit);
void add(StrolchTransaction tx, Audit audit);
public void addAll(StrolchTransaction tx, List<Audit> audits);
void addAll(StrolchTransaction tx, List<Audit> audits);
public void update(StrolchTransaction tx, Audit audit);
void update(StrolchTransaction tx, Audit audit);
public void updateAll(StrolchTransaction tx, List<Audit> audits);
void updateAll(StrolchTransaction tx, List<Audit> audits);
public void remove(StrolchTransaction tx, Audit audit);
void remove(StrolchTransaction tx, Audit audit);
public void removeAll(StrolchTransaction tx, List<Audit> audits);
void removeAll(StrolchTransaction tx, List<Audit> audits);
public long removeAll(StrolchTransaction tx, String type, DateRange dateRange);
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> query);
long removeAll(StrolchTransaction tx, String type, DateRange dateRange);
}

View File

@ -364,8 +364,6 @@ public interface ElementMap<T extends StrolchRootElement> {
* @param element
* the element to update
*
* @return the replaced element
*
* @throws StrolchPersistenceException
* if the element does not exist
*/
@ -379,8 +377,6 @@ public interface ElementMap<T extends StrolchRootElement> {
* @param elements
* the elements to update
*
* @return the replaced elements
*
* @throws StrolchPersistenceException
* if any of the elements don't yet exist
*/

View File

@ -1,12 +1,12 @@
/*
* 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.
@ -15,16 +15,11 @@
*/
package li.strolch.agent.api;
import java.util.List;
import li.strolch.model.Order;
import li.strolch.model.query.OrderQuery;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface OrderMap extends ElementMap<Order> {
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> query);
}

View File

@ -1,12 +1,12 @@
/*
* 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.
@ -15,16 +15,11 @@
*/
package li.strolch.agent.api;
import java.util.List;
import li.strolch.model.Resource;
import li.strolch.model.query.ResourceQuery;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ResourceMap extends ElementMap<Resource> {
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> query);
}

View File

@ -15,18 +15,11 @@
*/
package li.strolch.agent.impl;
import java.util.HashSet;
import java.util.List;
import li.strolch.agent.api.ActivityMap;
import li.strolch.agent.api.AuditTrail;
import li.strolch.agent.api.ElementMap;
import li.strolch.model.Tags;
import li.strolch.model.activity.Activity;
import li.strolch.model.query.ActivityQuery;
import li.strolch.model.visitor.ActivityVisitor;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.dbc.DBC;
/**
* This is the {@link AuditTrail} for {@link Activity Activities}
@ -49,18 +42,4 @@ public class AuditingActivityMap extends AuditingElementMapFacade<Activity> impl
protected ActivityMap getElementMap() {
return (ActivityMap) super.getElementMap();
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> query) {
ActivityVisitor<U> activityVisitor = query.getVisitor();
DBC.PRE.assertNotNull("activityVisitor on query", activityVisitor);
query.setVisitor(activity -> {
if (this.read == null)
this.read = new HashSet<>();
this.read.add(activity);
return activity.accept(activityVisitor);
});
return getElementMap().doQuery(tx, query);
}
}

View File

@ -19,8 +19,6 @@ import java.util.*;
import li.strolch.agent.api.AuditTrail;
import li.strolch.model.audit.Audit;
import li.strolch.model.audit.AuditVisitor;
import li.strolch.model.query.AuditQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.collections.DateRange;
import li.strolch.utils.dbc.DBC;
@ -40,16 +38,16 @@ import li.strolch.utils.dbc.DBC;
*/
public class AuditingAuditMapFacade implements AuditTrail {
private AuditTrail auditTrail;
private final AuditTrail auditTrail;
private Set<Audit> read;
private Set<Audit> created;
private Set<Audit> updated;
private Set<Audit> deleted;
private final Set<Audit> read;
private final Set<Audit> created;
private final Set<Audit> updated;
private final Set<Audit> deleted;
private long deletedAll;
private Map<String, Long> deletedAllByType;
private final Map<String, Long> deletedAllByType;
private boolean observeAccessReads;
private final boolean observeAccessReads;
public AuditingAuditMapFacade(AuditTrail auditTrail, boolean observeAccessReads) {
DBC.PRE.assertNotNull("auditTrail must be set!", auditTrail); //$NON-NLS-1$
@ -195,15 +193,4 @@ public class AuditingAuditMapFacade implements AuditTrail {
this.deletedAll += removed;
return removed;
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> query) {
AuditVisitor<U> auditVisitor = query.getVisitor();
query.setVisitor(audit -> {
this.read.add(audit);
return auditVisitor.visitAudit(audit);
});
return this.auditTrail.doQuery(tx, query);
}
}

View File

@ -15,18 +15,11 @@
*/
package li.strolch.agent.impl;
import java.util.HashSet;
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;
import li.strolch.model.Tags;
import li.strolch.model.query.OrderQuery;
import li.strolch.model.visitor.OrderVisitor;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.dbc.DBC;
/**
* This is the {@link AuditTrail} for {@link Order Orders}
@ -49,18 +42,4 @@ public class AuditingOrderMap extends AuditingElementMapFacade<Order> implements
protected OrderMap getElementMap() {
return (OrderMap) super.getElementMap();
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> query) {
OrderVisitor<U> orderVisitor = query.getVisitor();
DBC.PRE.assertNotNull("orderVisitor on query", orderVisitor);
query.setVisitor(order -> {
if (this.read == null)
this.read = new HashSet<>();
this.read.add(order);
return order.accept(orderVisitor);
});
return getElementMap().doQuery(tx, query);
}
}

View File

@ -15,18 +15,11 @@
*/
package li.strolch.agent.impl;
import java.util.HashSet;
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;
import li.strolch.model.Tags;
import li.strolch.model.query.ResourceQuery;
import li.strolch.model.visitor.ResourceVisitor;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.dbc.DBC;
/**
* This is the {@link AuditTrail} for {@link Resource Resources}
@ -49,18 +42,4 @@ public class AuditingResourceMap extends AuditingElementMapFacade<Resource> impl
protected ResourceMap getElementMap() {
return (ResourceMap) super.getElementMap();
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> query) {
ResourceVisitor<U> resourceVisitor = query.getVisitor();
DBC.PRE.assertNotNull("resourceVisitor on query", resourceVisitor);
query.setVisitor(resource -> {
if (this.read == null)
this.read = new HashSet<>();
this.read.add(resource);
return resource.accept(resourceVisitor);
});
return getElementMap().doQuery(tx, query);
}
}

View File

@ -17,17 +17,12 @@ package li.strolch.agent.impl;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ACTIVITY_REF;
import java.util.List;
import li.strolch.agent.api.ActivityMap;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.model.activity.Activity;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.ActivityQuery;
import li.strolch.persistence.api.ActivityDao;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryActivityQueryVisitor;
import li.strolch.runtime.query.inmemory.InMemoryQuery;
public class CachedActivityMap extends CachedElementMap<Activity> implements ActivityMap {
@ -44,11 +39,4 @@ public class CachedActivityMap extends CachedElementMap<Activity> implements Act
protected ActivityDao getDbDao(StrolchTransaction tx) {
return tx.getPersistenceHandler().getActivityDao(tx);
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> activityQuery) {
InMemoryActivityQueryVisitor visitor = new InMemoryActivityQueryVisitor();
InMemoryQuery<Activity, U> query = visitor.visit(activityQuery);
return query.doQuery(tx, this);
}
}

View File

@ -19,7 +19,6 @@ import java.text.MessageFormat;
import java.util.List;
import li.strolch.model.audit.Audit;
import li.strolch.model.query.AuditQuery;
import li.strolch.persistence.api.AuditDao;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.collections.DateRange;
@ -99,9 +98,4 @@ public class CachedAuditTrail extends TransientAuditTrail {
}
return removed;
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> query) {
return getDbDao(tx).doQuery(query);
}
}

View File

@ -32,7 +32,7 @@ import li.strolch.persistence.api.StrolchTransaction;
*/
public abstract class CachedElementMap<T extends StrolchRootElement> extends TransientElementMap<T> {
private StrolchRealm realm;
private final StrolchRealm realm;
public CachedElementMap(StrolchRealm realm) {
super();

View File

@ -18,17 +18,13 @@ package li.strolch.agent.impl;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ORDER_REF;
import java.util.Date;
import java.util.List;
import li.strolch.agent.api.OrderMap;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.model.Order;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.OrderQuery;
import li.strolch.persistence.api.OrderDao;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryOrderQueryVisitor;
import li.strolch.runtime.query.inmemory.InMemoryQuery;
public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap {
@ -52,11 +48,4 @@ public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap
protected OrderDao getDbDao(StrolchTransaction tx) {
return tx.getPersistenceHandler().getOrderDao(tx);
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> orderQuery) {
InMemoryOrderQueryVisitor visitor = new InMemoryOrderQueryVisitor();
InMemoryQuery<Order, U> query = visitor.visit(orderQuery);
return query.doQuery(tx, this);
}
}

View File

@ -17,17 +17,12 @@ package li.strolch.agent.impl;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_RESOURCE_REF;
import java.util.List;
import li.strolch.agent.api.ResourceMap;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.model.Resource;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.ResourceQuery;
import li.strolch.persistence.api.ResourceDao;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryQuery;
import li.strolch.runtime.query.inmemory.InMemoryResourceQueryVisitor;
public class CachedResourceMap extends CachedElementMap<Resource> implements ResourceMap {
@ -44,11 +39,4 @@ public class CachedResourceMap extends CachedElementMap<Resource> implements Res
protected ResourceDao getDbDao(StrolchTransaction tx) {
return tx.getPersistenceHandler().getResourceDao(tx);
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> resourceQuery) {
InMemoryResourceQueryVisitor visitor = new InMemoryResourceQueryVisitor();
InMemoryQuery<Resource, U> query = visitor.visit(resourceQuery);
return query.doQuery(tx, this);
}
}

View File

@ -20,7 +20,6 @@ import java.util.Set;
import li.strolch.agent.api.AuditTrail;
import li.strolch.model.audit.Audit;
import li.strolch.model.query.AuditQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.collections.DateRange;
@ -29,7 +28,7 @@ import li.strolch.utils.collections.DateRange;
*/
public class NoStrategyAuditTrail implements AuditTrail {
private String realm;
private final String realm;
public NoStrategyAuditTrail(String realm) {
this.realm = realm;
@ -104,9 +103,4 @@ public class NoStrategyAuditTrail implements AuditTrail {
public long removeAll(StrolchTransaction tx, String type, DateRange dateRange) {
return 0;
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> query) {
throw new IllegalStateException("Audit trail is not enabled for realm " + this.realm);
}
}

View File

@ -2,15 +2,9 @@ package li.strolch.agent.impl;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ACTIVITY_REF;
import java.util.List;
import li.strolch.agent.api.ActivityMap;
import li.strolch.model.activity.Activity;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.ActivityQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryActivityQueryVisitor;
import li.strolch.runtime.query.inmemory.InMemoryQuery;
public class TransientActivityMap extends TransientElementMap<Activity> implements ActivityMap {
@ -18,11 +12,4 @@ public class TransientActivityMap extends TransientElementMap<Activity> implemen
protected void assertIsRefParam(Parameter<?> refP) {
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ACTIVITY_REF, refP);
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> activityQuery) {
InMemoryActivityQueryVisitor visitor = new InMemoryActivityQueryVisitor();
InMemoryQuery<Activity, U> query = visitor.visit(activityQuery);
return query.doQuery(tx, this);
}
}

View File

@ -4,16 +4,13 @@ import java.util.*;
import li.strolch.agent.api.AuditTrail;
import li.strolch.model.audit.Audit;
import li.strolch.model.query.AuditQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryAuditQuery;
import li.strolch.runtime.query.inmemory.InMemoryAuditQueryVisitor;
import li.strolch.utils.collections.DateRange;
import li.strolch.utils.collections.MapOfMaps;
public class TransientAuditTrail implements AuditTrail {
private MapOfMaps<String, Long, Audit> auditMap;
private final MapOfMaps<String, Long, Audit> auditMap;
public TransientAuditTrail() {
this.auditMap = new MapOfMaps<>();
@ -140,11 +137,4 @@ public class TransientAuditTrail implements AuditTrail {
return toRemoveList.size();
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> auditQuery) {
InMemoryAuditQueryVisitor<U> visitor = new InMemoryAuditQueryVisitor<>();
InMemoryAuditQuery<U> query = visitor.toInMemory(auditQuery);
return query.doQuery(tx, this);
}
}

View File

@ -3,15 +3,11 @@ package li.strolch.agent.impl;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ORDER_REF;
import java.util.Date;
import java.util.List;
import li.strolch.agent.api.OrderMap;
import li.strolch.model.Order;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.OrderQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryOrderQueryVisitor;
import li.strolch.runtime.query.inmemory.InMemoryQuery;
public class TransientOrderMap extends TransientElementMap<Order> implements OrderMap {
@ -26,11 +22,4 @@ public class TransientOrderMap extends TransientElementMap<Order> implements Ord
protected void assertIsRefParam(Parameter<?> refP) {
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ORDER_REF, refP);
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> orderQuery) {
InMemoryOrderQueryVisitor visitor = new InMemoryOrderQueryVisitor();
InMemoryQuery<Order, U> query = visitor.visit(orderQuery);
return query.doQuery(tx, this);
}
}

View File

@ -2,15 +2,9 @@ package li.strolch.agent.impl;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_RESOURCE_REF;
import java.util.List;
import li.strolch.agent.api.ResourceMap;
import li.strolch.model.Resource;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.ResourceQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryQuery;
import li.strolch.runtime.query.inmemory.InMemoryResourceQueryVisitor;
public class TransientResourceMap extends TransientElementMap<Resource> implements ResourceMap {
@ -18,11 +12,4 @@ public class TransientResourceMap extends TransientElementMap<Resource> implemen
protected void assertIsRefParam(Parameter<?> refP) {
ElementMapHelpers.assertIsRefParam(INTERPRETATION_RESOURCE_REF, refP);
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> resourceQuery) {
InMemoryResourceQueryVisitor visitor = new InMemoryResourceQueryVisitor();
InMemoryQuery<Resource, U> query = visitor.visit(resourceQuery);
return query.doQuery(tx, this);
}
}

View File

@ -1,71 +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.query;
import java.util.Arrays;
import java.util.List;
import li.strolch.model.audit.AccessType;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ActionSelection extends AuditSelection {
private StringSelection actionSelection;
private List<AccessType> accessTypes;
public ActionSelection(AuditQuery<?> query) {
super(query);
}
public ActionSelection actions(StringMatchMode matchMode, String... actions) {
this.actionSelection = new StringSelection(matchMode, actions);
return this;
}
public ActionSelection accessTypes(List<AccessType> accessTypes) {
this.accessTypes = accessTypes;
return this;
}
public ActionSelection accessTypes(AccessType... accessTypes) {
this.accessTypes = Arrays.asList(accessTypes);
return this;
}
public List<AccessType> getAccessTypes() {
return this.accessTypes;
}
public StringSelection getActionSelection() {
return this.actionSelection;
}
public boolean isWildcardActionType() {
return this.accessTypes == null || this.accessTypes.isEmpty();
}
public boolean isWildcardAction() {
return this.actionSelection == null || this.actionSelection.isWildCard();
}
@Override
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,132 +0,0 @@
/*
* Copyright 2015 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.query;
import li.strolch.model.activity.Action;
import li.strolch.model.activity.Activity;
import li.strolch.model.query.ordering.StrolchQueryOrdering;
import li.strolch.model.visitor.ActivityVisitor;
import li.strolch.utils.dbc.DBC;
/**
* <p>
* {@link ActivityQuery} is the user API to query {@link Activity Activities} in Strolch. The {@link Navigation} is used
* to navigate to a type of activity on which any further {@link Selection Selections} will be performed. The
* {@link ActivityVisitor} is used to transform the returned object into a domain specific object (if required). This
* mechanism allows you to query e.g. a specific {@link Action} instead of having to return all the elements and then
* performing this transformation.
* </p>
*
* <p>
* The {@link ActivityVisitor} is intended for situations where the query result should not be {@link Activity} but some
* other object type. For instance in a restful API, the result might have to be mapped to a POJO, thus using this
* method can perform the mapping step for you
* </p>
*
* @param <U>
* defines the return type of this query. Depending on the user {@link ActivityVisitor} this query can return
* an {@link Activity}, or any type of object to which the visitor mapped the activity
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ActivityQuery<U> extends StrolchElementQuery<ActivityQueryVisitor> {
protected ActivityVisitor<U> visitor;
protected StrolchQueryOrdering ordering;
public ActivityQuery() {
super();
setIdentityVisitor();
}
public ActivityQuery(Navigation navigation) {
super(navigation);
setIdentityVisitor();
}
private void setIdentityVisitor() {
@SuppressWarnings("unchecked")
ActivityVisitor<U> identityVisitor = t -> (U) t;
this.visitor = identityVisitor;
}
public ActivityVisitor<U> getVisitor() {
return this.visitor;
}
@Override
public ActivityQuery<U> internal() {
super.internal();
return this;
}
public ActivityQuery<U> setVisitor(ActivityVisitor<U> visitor) {
DBC.PRE.assertNotNull("visitor", visitor);
this.visitor = visitor;
return this;
}
public StrolchQueryOrdering getOrdering() {
return this.ordering;
}
public ActivityQuery<U> setOrdering(StrolchQueryOrdering ordering) {
this.ordering = ordering;
return this;
}
@Override
public ActivityQuery<U> with(Selection selection) {
super.with(selection);
return this;
}
@Override
public ActivityQuery<U> not(Selection selection) {
super.not(selection);
return this;
}
@Override
public ActivityQuery<U> withAny() {
super.withAny();
return this;
}
@Override
public void accept(ActivityQueryVisitor visitor) {
super.accept(visitor);
if (this.ordering != null)
this.ordering.accept(visitor);
}
public static ActivityQuery<Activity> query(String type) {
return new ActivityQuery<>(new StrolchTypeNavigation(type));
}
public static ActivityQuery<Activity> query(String type, StrolchQueryOrdering ordering) {
return new ActivityQuery<Activity>(new StrolchTypeNavigation(type)).setOrdering(ordering);
}
public static <U> ActivityQuery<U> query(String type, ActivityVisitor<U> activityVisitor) {
return new ActivityQuery<U>(new StrolchTypeNavigation(type)).setVisitor(activityVisitor);
}
public static <U> ActivityQuery<U> query(String type, ActivityVisitor<U> activityVisitor,
StrolchQueryOrdering ordering) {
return new ActivityQuery<U>(new StrolchTypeNavigation(type)).setVisitor(activityVisitor).setOrdering(ordering);
}
}

View File

@ -1,27 +0,0 @@
/*
* Copyright 2015 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.query;
import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ActivityQueryVisitor
extends ActivitySelectionVisitor, ParameterSelectionVisitor, StrolchQueryOrderingVisitor {
// marker interface
}

View File

@ -1,35 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public abstract class ActivitySelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
accept((ActivitySelectionVisitor) visitor);
}
@Override
public boolean hasSelection() {
return true;
}
public abstract void accept(ActivitySelectionVisitor visitor);
}

View File

@ -1,24 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ActivitySelectionVisitor extends StrolchRootElementSelectionVisitor {
public void visit(ActivityStateSelection selection);
}

View File

@ -1,39 +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.query;
import li.strolch.model.State;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ActivityStateSelection extends ActivitySelection {
private State state;
public ActivityStateSelection(State state) {
this.state = state;
}
public State getState() {
return this.state;
}
@Override
public void accept(ActivitySelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,59 +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.query;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AndSelection extends BooleanSelection {
public AndSelection() {
super();
}
public AndSelection(Selection... selections) {
super(selections);
}
public AndSelection(List<Selection> selections) {
super(selections);
}
@Override
public AndSelection with(Selection selection) {
super.with(selection);
return this;
}
@Override
public AndSelection with(List<Selection> selections) {
super.with(selections);
return this;
}
@Override
public AndSelection with(Selection... selections) {
super.with(selections);
return this;
}
@Override
public void accept(QueryVisitor visitor) {
visitor.visitAnd(this);
}
}

View File

@ -1,32 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AnySelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
visitor.visitAny();
}
@Override
public boolean hasSelection() {
return true;
}
}

View File

@ -1,130 +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.query;
import java.util.ArrayList;
import java.util.List;
import li.strolch.model.audit.Audit;
import li.strolch.model.audit.AuditVisitor;
import li.strolch.model.audit.NoStrategyAuditVisitor;
import li.strolch.utils.collections.DateRange;
import li.strolch.utils.dbc.DBC;
/**
*
* <p>
* The {@link AuditVisitor} is intended for situations where the query result should not be {@link Audit} but some other
* object type. For instance in a restful API, the result might have to be mapped to a POJO, thus using this method can
* perform the mapping step for you
* </p>
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditQuery<U> implements StrolchQuery {
protected String elementTypeSelection;
protected List<AuditSelection> selections;
protected DateRange dateRange;
protected long limit;
protected AuditVisitor<U> auditVisitor;
public AuditQuery(AuditVisitor<U> auditVisitor, String elementTypeSelection, DateRange dateRange) {
DBC.PRE.assertNotNull("auditVisitor", auditVisitor);
DBC.PRE.assertNotEmpty("No elementTypeSelection (navigation) set!", elementTypeSelection); //$NON-NLS-1$
DBC.PRE.assertFalse("dateRange may not be unbounded!", dateRange.isUnbounded());
this.auditVisitor = auditVisitor;
this.elementTypeSelection = elementTypeSelection;
this.dateRange = dateRange;
this.selections = new ArrayList<>();
}
public AuditVisitor<U> getVisitor() {
return this.auditVisitor;
}
public AuditQuery<U> setVisitor(AuditVisitor<U> auditVisitor) {
DBC.PRE.assertNotNull("auditVisitor", auditVisitor);
this.auditVisitor = auditVisitor;
return this;
}
public String getElementTypeSelection() {
return this.elementTypeSelection;
}
public DateRange getDateRange() {
return this.dateRange;
}
public long getLimit() {
return limit;
}
public AuditQuery<U> limit(long limit) {
this.limit = limit;
return this;
}
public ActionSelection action() {
ActionSelection selection = new ActionSelection(this);
this.selections.add(selection);
return selection;
}
public ElementSelection element() {
ElementSelection selection = new ElementSelection(this);
this.selections.add(selection);
return selection;
}
public IdentitySelection identity() {
IdentitySelection selection = new IdentitySelection(this);
this.selections.add(selection);
return selection;
}
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
for (AuditSelection selection : this.selections) {
selection.accept(visitor);
}
}
/**
* @see li.strolch.privilege.model.Restrictable#getPrivilegeName()
*/
@Override
public String getPrivilegeName() {
return StrolchQuery.class.getName();
}
/**
* @see li.strolch.privilege.model.Restrictable#getPrivilegeValue()
*/
@Override
public Object getPrivilegeValue() {
return getClass().getName();
}
public static AuditQuery<Audit> query(String elementTypeSelection, DateRange dateRange) {
return new AuditQuery<>(new NoStrategyAuditVisitor(), elementTypeSelection, dateRange);
}
public static <U> AuditQuery<U> query(String elementTypeSelection, DateRange dateRange, AuditVisitor<U> orderVisitor) {
return new AuditQuery<>(orderVisitor, elementTypeSelection, dateRange);
}
}

View File

@ -1,30 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface AuditQueryVisitor {
public void visit(ElementSelection selection);
public void visit(IdentitySelection selection);
public void visit(ActionSelection selection);
public void visit(AuditQuery<?> auditQuery);
}

View File

@ -1,35 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AuditSelection {
private AuditQuery<?> query;
public AuditSelection(AuditQuery<?> query) {
super();
this.query = query;
}
public AuditQuery<?> query() {
return this.query;
}
public abstract void accept(AuditQueryVisitor visitor);
}

View File

@ -1,87 +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.query;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class BooleanSelection implements Selection {
protected List<Selection> selections;
public BooleanSelection() {
this.selections = new ArrayList<>(1);
}
public BooleanSelection(List<Selection> selections) {
this.selections = selections;
}
public BooleanSelection(Selection leftHandSide, Selection rightHandSide) {
this.selections = new ArrayList<>(2);
this.selections.add(leftHandSide);
this.selections.add(rightHandSide);
}
public BooleanSelection(Selection... selections) {
this.selections = new ArrayList<Selection>();
for (Selection selection : selections) {
this.selections.add(selection);
}
}
@Override
public boolean hasSelection() {
if (this.selections == null || this.selections.isEmpty())
return false;
for (Selection selection : this.selections) {
if (selection.hasSelection()) {
return true;
}
}
return false;
}
public List<Selection> getSelections() {
return Collections.unmodifiableList(this.selections);
}
public BooleanSelection with(Selection selection) {
this.selections.add(selection);
return this;
}
public BooleanSelection with(Selection... selections) {
for (Selection selection : selections) {
this.selections.add(selection);
}
return this;
}
public BooleanSelection with(List<Selection> selections) {
this.selections.addAll(selections);
return this;
}
@Override
public abstract void accept(QueryVisitor visitor);
}

View File

@ -1,83 +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.query;
import java.util.Date;
import li.strolch.utils.collections.DateRange;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class DateSelection extends OrderSelection {
private DateRange dateRange;
public DateSelection() {
this.dateRange = new DateRange();
}
public DateSelection(DateRange dateRange) {
this.dateRange = dateRange;
}
public DateSelection from(Date from, boolean inclusive) {
this.dateRange.from(from, inclusive);
return this;
}
public DateSelection to(Date to, boolean inclusive) {
this.dateRange.to(to, inclusive);
return this;
}
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);
}
public DateRange getDateRange() {
return this.dateRange;
}
@Override
public void accept(OrderSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,62 +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.query;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ElementSelection extends AuditSelection {
private StringSelection elementSubTypeSelection;
private StringSelection elementAccessedSelection;
public ElementSelection(AuditQuery<?> query) {
super(query);
}
public ElementSelection elementAccessed(StringMatchMode matchMode, String... elementsAccessed) {
this.elementAccessedSelection = new StringSelection(matchMode, elementsAccessed);
return this;
}
public StringSelection getElementAccessedSelection() {
return this.elementAccessedSelection;
}
public boolean isElementAccessedWildcard() {
return this.elementAccessedSelection == null || this.elementAccessedSelection.isWildCard();
}
public ElementSelection elementSubTypes(StringMatchMode matchMode, String... elementSubTypes) {
this.elementSubTypeSelection = new StringSelection(matchMode, elementSubTypes);
return this;
}
public StringSelection getElementSubTypeSelection() {
return this.elementSubTypeSelection;
}
public boolean isElementSubTypesWildcard() {
return this.elementSubTypeSelection == null || this.elementSubTypeSelection.isWildCard();
}
@Override
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,121 +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.query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class IdSelection extends StrolchElementSelection {
private List<String> ids;
private StringMatchMode matchMode;
/**
* Instantiate using {@link StringMatchMode#es()}
*
* @param id
*/
public IdSelection(String id) {
this.ids = new ArrayList<>(1);
this.ids.add(id);
this.matchMode = StringMatchMode.es();
}
/**
* @param id
* @param matchMode
*/
public IdSelection(String id, StringMatchMode matchMode) {
this.ids = new ArrayList<>(1);
this.ids.add(id);
this.matchMode = matchMode;
}
/**
* Instantiate using {@link StringMatchMode#es()}
*
* @param matchMode
* @param ids
*/
public IdSelection(String... ids) {
this.matchMode = StringMatchMode.es();
this.ids = Arrays.asList(ids);
}
/**
* @param matchMode
* @param ids
*/
public IdSelection(StringMatchMode matchMode, String... ids) {
this.matchMode = matchMode;
this.ids = Arrays.asList(ids);
}
/**
* @param ids
* @param matchMode
*/
public IdSelection(List<String> ids, StringMatchMode matchMode) {
this.matchMode = matchMode;
this.ids = ids;
}
/**
* Instantiate using {@link StringMatchMode#es()}
*
* @param ids
* @param matchMode
*/
public IdSelection(List<String> ids) {
this.matchMode = StringMatchMode.es();
this.ids = ids;
}
/**
* @return the ids
*/
public List<String> getIds() {
return this.ids;
}
/**
* @return the matchMode
*/
public StringMatchMode getMatchMode() {
return this.matchMode;
}
/**
* @param id
*
* @return
*/
public IdSelection with(String id) {
this.ids.add(id);
return this;
}
@Override
public void accept(StrolchElementSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,89 +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.query;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class IdentitySelection extends AuditSelection {
private StringSelection usernameSelection;
private StringSelection firstnameSelection;
private StringSelection lastnameSelection;
public IdentitySelection(AuditQuery<?> query) {
super(query);
}
public IdentitySelection usernames(StringMatchMode matchMode, String... usernames) {
this.usernameSelection = new StringSelection(matchMode, usernames);
return this;
}
public IdentitySelection firstnames(StringMatchMode matchMode, String... firstnames) {
this.firstnameSelection = new StringSelection(matchMode, firstnames);
return this;
}
public IdentitySelection lastnames(StringMatchMode matchMode, String... lastnames) {
this.lastnameSelection = new StringSelection(matchMode, lastnames);
return this;
}
/**
* @return the firstnameSelection
*/
public StringSelection getFirstnameSelection() {
return this.firstnameSelection;
}
/**
* @return the lastnameSelection
*/
public StringSelection getLastnameSelection() {
return this.lastnameSelection;
}
/**
* @return the usernameSelection
*/
public StringSelection getUsernameSelection() {
return this.usernameSelection;
}
public boolean isFirstnameWildcard() {
return this.firstnameSelection == null || this.firstnameSelection.isWildCard();
}
public boolean isLastnameWildcard() {
return this.lastnameSelection == null || this.lastnameSelection.isWildCard();
}
public boolean isUsernameWildcard() {
return this.usernameSelection == null || this.usernameSelection.isWildCard();
}
public boolean isWildcard() {
return isFirstnameWildcard() && isLastnameWildcard() && isUsernameWildcard();
}
@Override
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,55 +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.query;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NameSelection extends StrolchElementSelection {
private StringMatchMode matchMode;
private String name;
/**
* @param name
* @param matchMode
*/
public NameSelection(String name, StringMatchMode matchMode) {
this.name = name;
this.matchMode = matchMode;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @return the matchMode
*/
public StringMatchMode getMatchMode() {
return this.matchMode;
}
@Override
public void accept(StrolchElementSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,24 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface Navigation {
public void accept(QueryVisitor visitor);
}

View File

@ -1,47 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NotSelection extends BooleanSelection {
/**
* @param selection
*/
public NotSelection(Selection selection) {
super(selection);
}
/**
* @throws UnsupportedOperationException
* because a {@link NotSelection} can only work on a single {@link Selection}
*/
@Override
public NotSelection with(Selection selection) {
throw new UnsupportedOperationException("NotSelection can only have a single selection"); //$NON-NLS-1$
}
public Selection getSelection() {
return this.selections.get(0);
}
@Override
public void accept(QueryVisitor visitor) {
visitor.visitNot(this);
}
}

View File

@ -1,59 +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.query;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrSelection extends BooleanSelection {
public OrSelection() {
super();
}
public OrSelection(List<Selection> selections) {
super(selections);
}
public OrSelection(Selection... selections) {
super(selections);
}
@Override
public OrSelection with(Selection selection) {
super.with(selection);
return this;
}
@Override
public OrSelection with(List<Selection> selections) {
super.with(selections);
return this;
}
@Override
public OrSelection with(Selection... selections) {
super.with(selections);
return this;
}
@Override
public void accept(QueryVisitor visitor) {
visitor.visitOr(this);
}
}

View File

@ -1,132 +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.query;
import li.strolch.model.Order;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.ordering.StrolchQueryOrdering;
import li.strolch.model.visitor.OrderVisitor;
import li.strolch.utils.dbc.DBC;
/**
* <p>
* {@link OrderQuery} is the user API to query {@link Order Orders} in Strolch. The {@link Navigation} is used to
* navigate to a type of order on which any further {@link Selection Selections} will be performed. The
* {@link OrderVisitor} is used to transform the returned object into a domain specific object (if required). This
* mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and
* then performing this transformation.
* </p>
*
* <p>
* The {@link OrderVisitor} is intended for situations where the query result should not be {@link Order} but some other
* object type. For instance in a restful API, the result might have to be mapped to a POJO, thus using this method can
* perform the mapping step for you
* </p>
*
* @param <U>
* defines the return type of this query. Depending on the user {@link OrderVisitor} this query can return an
* {@link Order}, or any type of object to which the visitor mapped the order
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderQuery<U> extends StrolchElementQuery<OrderQueryVisitor> {
protected OrderVisitor<U> orderVisitor;
protected StrolchQueryOrdering ordering;
public OrderQuery() {
super();
setIdentityVisitor();
}
public OrderQuery(Navigation navigation) {
super(navigation);
setIdentityVisitor();
}
private void setIdentityVisitor() {
@SuppressWarnings("unchecked")
OrderVisitor<U> identityVisitor = t -> (U) t;
this.orderVisitor = identityVisitor;
}
public OrderVisitor<U> getVisitor() {
return this.orderVisitor;
}
@Override
public OrderQuery<U> internal() {
super.internal();
return this;
}
public OrderQuery<U> setVisitor(OrderVisitor<U> visitor) {
DBC.PRE.assertNotNull("visitor", visitor);
this.orderVisitor = visitor;
return this;
}
public StrolchQueryOrdering getOrdering() {
return this.ordering;
}
public OrderQuery<U> setOrdering(StrolchQueryOrdering ordering) {
this.ordering = ordering;
return this;
}
@Override
public OrderQuery<U> with(Selection selection) {
super.with(selection);
return this;
}
@Override
public OrderQuery<U> not(Selection selection) {
super.not(selection);
return this;
}
@Override
public OrderQuery<U> withAny() {
super.withAny();
return this;
}
@Override
public void accept(OrderQueryVisitor visitor) {
DBC.PRE.assertNotNull("orderVisitor", this.orderVisitor);
super.accept(visitor);
if (this.ordering != null)
this.ordering.accept(visitor);
}
public static OrderQuery<Order> query(String type) {
return new OrderQuery<>(new StrolchTypeNavigation(type));
}
public static OrderQuery<Order> query(String type, StrolchQueryOrdering ordering) {
return new OrderQuery<Order>(new StrolchTypeNavigation(type)).setOrdering(ordering);
}
public static <U> OrderQuery<U> query(String type, OrderVisitor<U> orderVisitor) {
return new OrderQuery<U>(new StrolchTypeNavigation(type)).setVisitor(orderVisitor);
}
public static <U> OrderQuery<U> query(String type, OrderVisitor<U> orderVisitor, StrolchQueryOrdering ordering) {
return new OrderQuery<U>(new StrolchTypeNavigation(type)).setVisitor(orderVisitor).setOrdering(ordering);
}
}

View File

@ -1,27 +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.query;
import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface OrderQueryVisitor extends OrderSelectionVisitor, ParameterSelectionVisitor,
StrolchQueryOrderingVisitor {
// marker interface
}

View File

@ -1,35 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public abstract class OrderSelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
accept((OrderSelectionVisitor) visitor);
}
@Override
public boolean hasSelection() {
return true;
}
public abstract void accept(OrderSelectionVisitor visitor);
}

View File

@ -1,26 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface OrderSelectionVisitor extends StrolchRootElementSelectionVisitor {
public void visit(DateSelection selection);
public void visit(OrderStateSelection selection);
}

View File

@ -1,39 +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.query;
import li.strolch.model.State;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderStateSelection extends OrderSelection {
private State state;
public OrderStateSelection(State state) {
this.state = state;
}
public State getState() {
return this.state;
}
@Override
public void accept(OrderSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,71 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ParameterBagSelection implements Selection {
private String bagKey;
public ParameterBagSelection(String bagKey) {
this.bagKey = bagKey;
}
/**
* @return the bagKey
*/
public String getBagKey() {
return this.bagKey;
}
@Override
public boolean hasSelection() {
return true;
}
@Override
public void accept(QueryVisitor visitor) {
accept((StrolchRootElementSelectionVisitor) visitor);
}
public void accept(StrolchRootElementSelectionVisitor visitor) {
visitor.visit(this);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName() + " [bagKey=");
builder.append(this.bagKey);
builder.append("]");
return builder.toString();
}
public static class NullParameterBagSelection extends ParameterBagSelection {
public NullParameterBagSelection(String bagKey) {
super(bagKey);
}
@Override
public void accept(StrolchRootElementSelectionVisitor visitor) {
visitor.visit(this);
}
}
}

View File

@ -1,408 +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.query;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import li.strolch.utils.StringMatchMode;
import li.strolch.utils.collections.DateRange;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class ParameterSelection implements Selection {
private String bagKey;
private String paramKey;
public ParameterSelection(String bagKey, String paramKey) {
this.bagKey = bagKey;
this.paramKey = paramKey;
}
/**
* @return the bagKey
*/
public String getBagKey() {
return this.bagKey;
}
/**
* @return the paramKey
*/
public String getParamKey() {
return this.paramKey;
}
@Override
public boolean hasSelection() {
return true;
}
@Override
public void accept(QueryVisitor visitor) {
accept((ParameterSelectionVisitor) visitor);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName() + " [bagKey=");
builder.append(this.bagKey);
builder.append(", paramKey=");
builder.append(this.paramKey);
builder.append("]");
return builder.toString();
}
public abstract void accept(ParameterSelectionVisitor visitor);
public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value,
StringMatchMode matchMode) {
return new StringParameterSelection(bagKey, paramKey, value, matchMode);
}
public static IntegerParameterSelection integerSelection(String bagKey, String paramKey, int value) {
return new IntegerParameterSelection(bagKey, paramKey, value);
}
public static BooleanParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) {
return new BooleanParameterSelection(bagKey, paramKey, value);
}
public static FloatParameterSelection floatSelection(String bagKey, String paramKey, double value) {
return new FloatParameterSelection(bagKey, paramKey, value);
}
public static LongParameterSelection longSelection(String bagKey, String paramKey, long value) {
return new LongParameterSelection(bagKey, paramKey, value);
}
public static DateParameterSelection dateSelection(String bagKey, String paramKey, Date value) {
return new DateParameterSelection(bagKey, paramKey, value);
}
public static DateRangeParameterSelection dateRangeSelection(String bagKey, String paramKey, DateRange dateRange) {
return new DateRangeParameterSelection(bagKey, paramKey, dateRange);
}
public static StringListParameterSelection stringListSelection(String bagKey, String paramKey, String value) {
return new StringListParameterSelection(bagKey, paramKey, Arrays.asList(value));
}
public static StringListParameterSelection stringListSelection(String bagKey, String paramKey, List<String> value) {
return new StringListParameterSelection(bagKey, paramKey, value);
}
public static IntegerListParameterSelection integerListSelection(String bagKey, String paramKey, Integer value) {
return new IntegerListParameterSelection(bagKey, paramKey, Arrays.asList(value));
}
public static IntegerListParameterSelection integerListSelection(String bagKey, String paramKey,
List<Integer> value) {
return new IntegerListParameterSelection(bagKey, paramKey, value);
}
public static FloatListParameterSelection floatListSelection(String bagKey, String paramKey, Double value) {
return new FloatListParameterSelection(bagKey, paramKey, Arrays.asList(value));
}
public static FloatListParameterSelection floatListSelection(String bagKey, String paramKey, List<Double> value) {
return new FloatListParameterSelection(bagKey, paramKey, value);
}
public static LongListParameterSelection longListSelection(String bagKey, String paramKey, Long value) {
return new LongListParameterSelection(bagKey, paramKey, Arrays.asList(value));
}
public static LongListParameterSelection longListSelection(String bagKey, String paramKey, List<Long> value) {
return new LongListParameterSelection(bagKey, paramKey, value);
}
public static NullParameterSelection nullSelection(String bagKey, String paramKey) {
return new NullParameterSelection(bagKey, paramKey);
}
public static AnyTypeParameterSelection anyTypeSelection(String bagKey, String paramKey, String value,
StringMatchMode matchMode) {
return new AnyTypeParameterSelection(bagKey, paramKey, value, matchMode);
}
public static class AnyTypeParameterSelection extends ParameterSelection {
private StringMatchMode matchMode;
private String value;
public AnyTypeParameterSelection(String bagKey, String paramKey, String value, StringMatchMode matchMode) {
super(bagKey, paramKey);
this.value = value;
this.matchMode = matchMode;
}
public String getValue() {
return this.value;
}
public StringMatchMode getMatchMode() {
return this.matchMode;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class NullParameterSelection extends ParameterSelection {
public NullParameterSelection(String bagKey, String paramKey) {
super(bagKey, paramKey);
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class StringParameterSelection extends ParameterSelection {
private StringMatchMode matchMode;
private String value;
public StringParameterSelection(String bagKey, String paramKey, String value, StringMatchMode matchMode) {
super(bagKey, paramKey);
this.value = value;
this.matchMode = matchMode;
}
public String getValue() {
return this.value;
}
public StringMatchMode getMatchMode() {
return this.matchMode;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class IntegerParameterSelection extends ParameterSelection {
private Integer value;
public IntegerParameterSelection(String bagKey, String paramKey, Integer value) {
super(bagKey, paramKey);
this.value = value;
}
public Integer getValue() {
return this.value;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class BooleanParameterSelection extends ParameterSelection {
private Boolean value;
public BooleanParameterSelection(String bagKey, String paramKey, Boolean value) {
super(bagKey, paramKey);
this.value = value;
}
public Boolean getValue() {
return this.value;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class LongParameterSelection extends ParameterSelection {
private Long value;
public LongParameterSelection(String bagKey, String paramKey, Long value) {
super(bagKey, paramKey);
this.value = value;
}
public Long getValue() {
return this.value;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class FloatParameterSelection extends ParameterSelection {
private Double value;
public FloatParameterSelection(String bagKey, String paramKey, Double value) {
super(bagKey, paramKey);
this.value = value;
}
public Double getValue() {
return this.value;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class DateParameterSelection extends ParameterSelection {
private Date value;
public DateParameterSelection(String bagKey, String paramKey, Date value) {
super(bagKey, paramKey);
this.value = value;
}
public Date getValue() {
return this.value;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class DateRangeParameterSelection extends ParameterSelection {
private DateRange dateRange;
public DateRangeParameterSelection(String bagKey, String paramKey, DateRange dateRange) {
super(bagKey, paramKey);
DBC.PRE.assertFalse("dateRange must be set!", dateRange == null); //$NON-NLS-1$
this.dateRange = dateRange;
}
public DateRange getDateRange() {
return this.dateRange;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class DurationParameterSelection extends ParameterSelection {
private Long value;
public DurationParameterSelection(String bagKey, String paramKey, Long value) {
super(bagKey, paramKey);
this.value = value;
}
public Long getValue() {
return this.value;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static abstract class AbstractListParameterSelection<T> extends ParameterSelection {
private List<T> value;
public AbstractListParameterSelection(String bagKey, String paramKey, List<T> value) {
super(bagKey, paramKey);
this.value = value;
}
public List<T> getValue() {
return this.value;
}
@Override
public abstract void accept(ParameterSelectionVisitor visitor);
}
public static class StringListParameterSelection extends AbstractListParameterSelection<String> {
public StringListParameterSelection(String bagKey, String paramKey, List<String> value) {
super(bagKey, paramKey, value);
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class IntegerListParameterSelection extends AbstractListParameterSelection<Integer> {
public IntegerListParameterSelection(String bagKey, String paramKey, List<Integer> value) {
super(bagKey, paramKey, value);
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class FloatListParameterSelection extends AbstractListParameterSelection<Double> {
public FloatListParameterSelection(String bagKey, String paramKey, List<Double> value) {
super(bagKey, paramKey, value);
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class LongListParameterSelection extends AbstractListParameterSelection<Long> {
public LongListParameterSelection(String bagKey, String paramKey, List<Long> value) {
super(bagKey, paramKey, value);
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
}

View File

@ -1,65 +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.query;
import li.strolch.model.query.ParameterSelection.AnyTypeParameterSelection;
import li.strolch.model.query.ParameterSelection.BooleanParameterSelection;
import li.strolch.model.query.ParameterSelection.DateParameterSelection;
import li.strolch.model.query.ParameterSelection.DateRangeParameterSelection;
import li.strolch.model.query.ParameterSelection.DurationParameterSelection;
import li.strolch.model.query.ParameterSelection.FloatListParameterSelection;
import li.strolch.model.query.ParameterSelection.FloatParameterSelection;
import li.strolch.model.query.ParameterSelection.IntegerListParameterSelection;
import li.strolch.model.query.ParameterSelection.IntegerParameterSelection;
import li.strolch.model.query.ParameterSelection.LongListParameterSelection;
import li.strolch.model.query.ParameterSelection.LongParameterSelection;
import li.strolch.model.query.ParameterSelection.NullParameterSelection;
import li.strolch.model.query.ParameterSelection.StringListParameterSelection;
import li.strolch.model.query.ParameterSelection.StringParameterSelection;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ParameterSelectionVisitor extends QueryVisitor {
public void visit(StringParameterSelection selection);
public void visit(IntegerParameterSelection selection);
public void visit(BooleanParameterSelection selection);
public void visit(LongParameterSelection selection);
public void visit(FloatParameterSelection selection);
public void visit(DateParameterSelection selection);
public void visit(DurationParameterSelection selection);
public void visit(DateRangeParameterSelection selection);
public void visit(StringListParameterSelection selection);
public void visit(IntegerListParameterSelection selection);
public void visit(FloatListParameterSelection selection);
public void visit(LongListParameterSelection selection);
public void visit(NullParameterSelection selection);
public void visit(AnyTypeParameterSelection selection);
}

View File

@ -1,32 +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.query;
import li.strolch.model.visitor.StrolchVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface QueryVisitor extends StrolchVisitor {
public void visitAny();
public void visitAnd(AndSelection andSelection);
public void visitOr(OrSelection orSelection);
public void visitNot(NotSelection notSelection);
}

View File

@ -1,133 +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.query;
import li.strolch.model.Resource;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.query.ordering.StrolchQueryOrdering;
import li.strolch.model.visitor.ResourceVisitor;
import li.strolch.utils.dbc.DBC;
/**
* <p>
* {@link ResourceQuery} is the user API to query {@link Resource Resources} in Strolch. The {@link Navigation} is used
* to navigate to a type of resource on which any further {@link Selection Selections} will be performed. The
* {@link ResourceVisitor} is used to transform the returned object into a domain specific object (if required). This
* mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and
* then performing this transformation.
* </p>
*
* <p>
* The {@link ResourceVisitor} is intended for situations where the query result should not be {@link Resource} but some
* other object type. For instance in a restful API, the result might have to be mapped to a POJO, thus using this
* method can perform the mapping step for you
* </p>
*
* @param <U>
* defines the return type of this query. Depending on the user {@link ResourceVisitor} this query can return
* a {@link Resource}, or any type of object to which the visitor mapped the resource
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ResourceQuery<U> extends StrolchElementQuery<ResourceQueryVisitor> {
protected ResourceVisitor<U> resourceVisitor;
protected StrolchQueryOrdering ordering;
public ResourceQuery() {
super();
setIdentityVisitor();
}
public ResourceQuery(Navigation navigation) {
super(navigation);
setIdentityVisitor();
}
private void setIdentityVisitor() {
@SuppressWarnings("unchecked")
ResourceVisitor<U> identityVisitor = t -> (U) t;
this.resourceVisitor = identityVisitor;
}
public ResourceVisitor<U> getVisitor() {
return this.resourceVisitor;
}
@Override
public ResourceQuery<U> internal() {
super.internal();
return this;
}
public ResourceQuery<U> setVisitor(ResourceVisitor<U> visitor) {
DBC.PRE.assertNotNull("visitor", visitor);
this.resourceVisitor = visitor;
return this;
}
public StrolchQueryOrdering getOrdering() {
return this.ordering;
}
public ResourceQuery<U> setOrdering(StrolchQueryOrdering ordering) {
this.ordering = ordering;
return this;
}
@Override
public ResourceQuery<U> with(Selection selection) {
super.with(selection);
return this;
}
@Override
public ResourceQuery<U> not(Selection selection) {
super.not(selection);
return this;
}
@Override
public ResourceQuery<U> withAny() {
super.withAny();
return this;
}
@Override
public void accept(ResourceQueryVisitor visitor) {
DBC.PRE.assertNotNull("resourceVisitor", this.resourceVisitor);
super.accept(visitor);
if (this.ordering != null)
this.ordering.accept(visitor);
}
public static ResourceQuery<Resource> query(String type) {
return new ResourceQuery<>(new StrolchTypeNavigation(type));
}
public static ResourceQuery<Resource> query(String type, StrolchQueryOrdering ordering) {
return new ResourceQuery<Resource>(new StrolchTypeNavigation(type)).setOrdering(ordering);
}
public static <U> ResourceQuery<U> query(String type, ResourceVisitor<U> resourceVisitor) {
return new ResourceQuery<U>(new StrolchTypeNavigation(type)).setVisitor(resourceVisitor);
}
public static <U> ResourceQuery<U> query(String type, ResourceVisitor<U> resourceVisitor,
StrolchQueryOrdering ordering) {
return new ResourceQuery<U>(new StrolchTypeNavigation(type)).setVisitor(resourceVisitor).setOrdering(ordering);
}
}

View File

@ -1,27 +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.query;
import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ResourceQueryVisitor extends StrolchRootElementSelectionVisitor, ParameterSelectionVisitor,
StrolchQueryOrderingVisitor {
// marker interface
}

View File

@ -1,30 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface Selection {
public void accept(QueryVisitor visitor);
public boolean hasSelection();
public default Selection not() {
return new NotSelection(this);
}
}

View File

@ -1,85 +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.query;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class StringSelection {
private StringMatchMode matchMode;
private String[] values;
public StringSelection() {
//
}
/**
* @param matchMode
* @param values
*/
public StringSelection(StringMatchMode matchMode, String[] values) {
this.matchMode = matchMode;
this.values = values;
}
/**
* @return the matchMode
*/
public StringMatchMode getMatchMode() {
return this.matchMode;
}
/**
* @param matchMode
* the matchMode to set
*/
public void setMatchMode(StringMatchMode matchMode) {
this.matchMode = matchMode;
}
/**
* @return the values
*/
public String[] getValues() {
return this.values;
}
/**
* @param values
* the values to set
*/
public void setValues(String... values) {
this.values = values;
}
/**
* @return
*/
public boolean isWildCard() {
return this.values == null || this.values.length == 0;
}
public boolean matches(String value) {
for (String sel : this.values) {
if (this.matchMode.matches(value, sel))
return true;
}
return false;
}
}

View File

@ -1,135 +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.query;
import static li.strolch.model.StrolchModelConstants.INTERNAL;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class StrolchElementQuery<T extends QueryVisitor> implements StrolchQuery {
private String privilegeValue;
protected Navigation navigation;
protected Selection selection;
public StrolchElementQuery() {
this.privilegeValue = getClass().getName();
}
public StrolchElementQuery(Navigation navigation) {
this();
this.navigation = navigation;
}
/**
* Marks this query as an internal query, thus allowing it to be performed without the authenticated user to need
* the required privilege
*
* @return this object for chaining
*/
public StrolchElementQuery<T> internal() {
this.privilegeValue = INTERNAL;
return this;
}
public void setPrivilegeValue(String privilegeValue) {
this.privilegeValue = privilegeValue;
}
public void setNavigation(Navigation navigation) {
this.navigation = navigation;
}
public boolean hasNavigation() {
return this.navigation != null;
}
public Navigation getNavigation() {
return this.navigation;
}
public boolean hasSelection() {
return this.selection != null && this.selection.hasSelection();
}
public Selection getSelection() {
return this.selection;
}
public StrolchElementQuery<T> with(Selection selection) {
assertNoSelectionYetSet();
this.selection = selection;
return this;
}
private void assertNoSelectionYetSet() {
String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$
DBC.PRE.assertNull(msg, this.selection);
}
public StrolchElementQuery<T> withAny() {
assertNoSelectionYetSet();
this.selection = new AnySelection();
return this;
}
public AndSelection and() {
assertNoSelectionYetSet();
AndSelection and = new AndSelection();
this.selection = and;
return and;
}
public OrSelection or() {
assertNoSelectionYetSet();
OrSelection or = new OrSelection();
this.selection = or;
return or;
}
public StrolchElementQuery<T> not(Selection selection) {
assertNoSelectionYetSet();
this.selection = new NotSelection(selection);
return this;
}
public void accept(T visitor) {
DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$
DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$
this.navigation.accept(visitor);
this.selection.accept(visitor);
}
/**
* @see li.strolch.privilege.model.Restrictable#getPrivilegeName()
*/
@Override
public String getPrivilegeName() {
return StrolchQuery.class.getName();
}
/**
* @see li.strolch.privilege.model.Restrictable#getPrivilegeValue()
*/
@Override
public Object getPrivilegeValue() {
return this.privilegeValue;
}
}

View File

@ -1,34 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class StrolchElementSelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
accept((StrolchElementSelectionVisitor) visitor);
}
@Override
public boolean hasSelection() {
return true;
}
public abstract void accept(StrolchElementSelectionVisitor visitor);
}

View File

@ -1,28 +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.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchElementSelectionVisitor extends QueryVisitor {
public void visit(StrolchTypeNavigation navigation);
public void visit(IdSelection selection);
public void visit(NameSelection selection);
}

View File

@ -1,26 +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.query;
import li.strolch.privilege.model.Restrictable;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchQuery extends Restrictable {
// marker interface
}

View File

@ -1,28 +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.query;
import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchRootElementSelectionVisitor extends StrolchElementSelectionVisitor {
public void visit(ParameterBagSelection selection);
public void visit(NullParameterBagSelection selection);
}

View File

@ -1,44 +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.query;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class StrolchTypeNavigation implements Navigation {
private String type;
public StrolchTypeNavigation(String type) {
DBC.PRE.assertNotEmpty("type", type);
this.type = type;
}
public String getType() {
return this.type;
}
@Override
public void accept(QueryVisitor visitor) {
accept((StrolchElementSelectionVisitor) visitor);
}
public void accept(StrolchElementSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,25 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*/
package li.strolch.model.query.ordering;
import java.util.Comparator;
import li.strolch.model.StrolchRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ByIdComparator<T extends StrolchRootElement> implements Comparator<T> {
private boolean ascending;
public ByIdComparator(boolean ascending) {
this.ascending = ascending;
}
@Override
public int compare(T o1, T o2) {
return this.ascending ? o1.getId().compareTo(o2.getId()) : o2.getId().compareTo(o1.getId());
}
}

View File

@ -1,25 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*/
package li.strolch.model.query.ordering;
import java.util.Comparator;
import li.strolch.model.StrolchRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ByNameComparator<T extends StrolchRootElement> implements Comparator<T> {
private boolean ascending;
public ByNameComparator(boolean ascending) {
this.ascending = ascending;
}
@Override
public int compare(T o1, T o2) {
return this.ascending ? o1.getName().compareTo(o2.getName()) : o2.getName().compareTo(o1.getName());
}
}

View File

@ -1,42 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*/
package li.strolch.model.query.ordering;
import java.util.Comparator;
import li.strolch.exception.StrolchException;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.parameter.Parameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ByParamComparator<T extends StrolchRootElement> implements Comparator<T> {
private String bagKey;
private String paramKey;
private boolean ascending;
public ByParamComparator(String bagKey, String paramKey, boolean ascending) {
this.bagKey = bagKey;
this.paramKey = paramKey;
this.ascending = ascending;
}
@Override
public int compare(T o1, T o2) {
Parameter<?> param1 = o1.getParameter(bagKey, paramKey);
if (param1 == null)
throw new StrolchException("Sorting parameter bag=" + bagKey + ", param=" + paramKey + " does not exist on "
+ o1.getLocator());
Parameter<?> param2 = o2.getParameter(bagKey, paramKey);
if (param2 == null)
throw new StrolchException("Sorting parameter bag=" + bagKey + ", param=" + paramKey + " does not exist on "
+ o2.getLocator());
return this.ascending ? param1.compareTo(param2) : param2.compareTo(param1);
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2015 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.query.ordering;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderById extends StrolchQueryOrdering {
/**
* Creates this ordering with ascending order
*/
public OrderById() {
super(true);
}
/**
* Creates this ordering the given ascending order
*
* @param ascending
* true for ascending, false for descending order
*/
public OrderById(boolean ascending) {
super(ascending);
}
@Override
public void accept(StrolchQueryOrderingVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2015 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.query.ordering;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderByName extends StrolchQueryOrdering {
/**
* Creates this ordering with ascending order
*/
public OrderByName() {
super(true);
}
/**
* Creates this ordering the given ascending order
*
* @param ascending
* true for ascending, false for descending order
*/
public OrderByName(boolean ascending) {
super(ascending);
}
@Override
public void accept(StrolchQueryOrderingVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,71 +0,0 @@
/*
* Copyright 2015 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.query.ordering;
import li.strolch.model.ParameterBag;
import li.strolch.model.parameter.Parameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderByParameter extends StrolchQueryOrdering {
private String bagKey;
private String paramKey;
/**
* Creates this ordering with the given bagKey and paramKey with ascending order
*
* @param bagKey
* the {@link ParameterBag} in which to retrieve the {@link Parameter} for ordering
* @param paramKey
* the {@link Parameter} with which to order
*/
public OrderByParameter(String bagKey, String paramKey) {
super(true);
this.bagKey = bagKey;
this.paramKey = paramKey;
}
/**
* Creates this ordering with the given bagKey and paramKey and ascending order
*
* @param ascending
* true for ascending, false for descending order
* @param bagKey
* the {@link ParameterBag} in which to retrieve the {@link Parameter} for ordering
* @param paramKey
* the {@link Parameter} with which to order
*/
public OrderByParameter(boolean ascending, String bagKey, String paramKey) {
super(ascending);
this.bagKey = bagKey;
this.paramKey = paramKey;
}
public String getBagKey() {
return this.bagKey;
}
public String getParamKey() {
return this.paramKey;
}
@Override
public void accept(StrolchQueryOrderingVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,38 +0,0 @@
/*
* Copyright 2015 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.query.ordering;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class StrolchQueryOrdering {
private boolean ascending;
public StrolchQueryOrdering(boolean ascending) {
this.ascending = ascending;
}
public boolean isAscending() {
return this.ascending;
}
public void setAscending(boolean ascending) {
this.ascending = ascending;
}
public abstract void accept(StrolchQueryOrderingVisitor visitor);
}

View File

@ -1,28 +0,0 @@
/*
* Copyright 2015 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.query.ordering;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchQueryOrderingVisitor {
public StrolchQueryOrderingVisitor visit(OrderById orderById);
public StrolchQueryOrderingVisitor visit(OrderByName orderByName);
public StrolchQueryOrderingVisitor visit(OrderByParameter orderByParameter);
}

View File

@ -1,18 +1,3 @@
/*
* 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.persistence.api;
import static li.strolch.agent.api.StrolchAgent.getUniqueId;
@ -28,7 +13,6 @@ import java.util.stream.Stream;
import li.strolch.agent.api.*;
import li.strolch.agent.impl.*;
import li.strolch.exception.StrolchAccessDeniedException;
import li.strolch.exception.StrolchException;
import li.strolch.exception.StrolchModelException;
import li.strolch.handler.operationslog.OperationsLog;
@ -45,7 +29,6 @@ import li.strolch.model.parameter.Parameter;
import li.strolch.model.parameter.StringListParameter;
import li.strolch.model.parameter.StringParameter;
import li.strolch.model.policy.PolicyDef;
import li.strolch.model.query.*;
import li.strolch.model.timedstate.StrolchTimedState;
import li.strolch.model.timevalue.IValue;
import li.strolch.policy.PolicyHandler;
@ -58,7 +41,6 @@ import li.strolch.privilege.model.Restrictable;
import li.strolch.runtime.privilege.PrivilegeHandler;
import li.strolch.runtime.privilege.TransactedRestrictable;
import li.strolch.service.api.Command;
import li.strolch.utils.I18nMessage;
import li.strolch.utils.collections.MapOfMaps;
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.helper.StringHelper;
@ -73,10 +55,10 @@ public abstract class AbstractTransaction implements StrolchTransaction {
protected static final Logger logger = LoggerFactory.getLogger(AbstractTransaction.class);
private ComponentContainer container;
private PrivilegeHandler privilegeHandler;
private InternalStrolchRealm realm;
private final ComponentContainer container;
private final PrivilegeHandler privilegeHandler;
private final InternalStrolchRealm realm;
private final TransactionResult txResult;
private ObjectFilter objectFilter;
private MapOfMaps<String, String, Resource> resourceCache;
@ -88,19 +70,18 @@ public abstract class AbstractTransaction implements StrolchTransaction {
private boolean suppressUpdates;
private boolean suppressAudits;
private boolean suppressAuditsForAudits;
private TransactionResult txResult;
private List<Command> commands;
private List<Command> flushedCommands;
private Set<Locator> lockedElements;
private final List<Command> flushedCommands;
private final Set<Locator> lockedElements;
private AuditingOrderMap orderMap;
private AuditingResourceMap resourceMap;
private AuditingActivityMap activityMap;
private AuditingAuditMapFacade auditTrail;
private String action;
private Certificate certificate;
private final String action;
private final Certificate certificate;
private PrivilegeContext privilegeContext;
public AbstractTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate, String action,
@ -446,64 +427,6 @@ public abstract class AbstractTransaction implements StrolchTransaction {
return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, defaultDef, this);
}
private void assertQueryAllowed(StrolchQuery query) {
try {
getPrivilegeContext().validateAction(query);
} catch (AccessDeniedException e) {
String username = getCertificate().getUsername();
if (getContainer().hasComponent(OperationsLog.class)) {
String realmName = getRealmName();
String queryName = query.getPrivilegeValue().equals(INTERNAL) ?
(getClass().getName() + " (INTERNAL)") :
query.getPrivilegeValue().toString();
LogMessage logMessage = new LogMessage(realmName, username,
Locator.valueOf(AGENT, PrivilegeHandler.class.getSimpleName(), query.getPrivilegeName(),
queryName), LogSeverity.Exception, LogMessageState.Information,
ResourceBundle.getBundle("strolch-agent"), "agent.query.failed.access.denied")
.value("user", username).value("query", queryName).withException(e);
OperationsLog operationsLog = getContainer().getComponent(OperationsLog.class);
operationsLog.addMessage(logMessage);
}
String queryName = query.getPrivilegeValue().equals(INTERNAL) ?
(getClass().getSimpleName() + " (INTERNAL)") :
query.getClass().getSimpleName();
I18nMessage i18n = new I18nMessage(ResourceBundle.getBundle("strolch-agent", getCertificate().getLocale()),
"agent.search.failed.access.denied").value("user", username).value("query", queryName);
throw new StrolchAccessDeniedException(this.certificate, query, i18n, e);
}
}
@Override
public <U> List<U> doQuery(OrderQuery<U> query) {
assertQueryAllowed(query);
DBC.PRE.assertNotNull("orderVisitor", query.getVisitor());
return getOrderMap().doQuery(this, query);
}
@Override
public <U> List<U> doQuery(ResourceQuery<U> query) {
assertQueryAllowed(query);
DBC.PRE.assertNotNull("resourceVisitor", query.getVisitor());
return getResourceMap().doQuery(this, query);
}
@Override
public <U> List<U> doQuery(ActivityQuery<U> query) {
assertQueryAllowed(query);
DBC.PRE.assertNotNull("activityVisitor", query.getVisitor());
return getActivityMap().doQuery(this, query);
}
@Override
public <U> List<U> doQuery(AuditQuery<U> query) {
assertQueryAllowed(query);
DBC.PRE.assertNotNull("auditVisitor", query.getVisitor());
return getAuditTrail().doQuery(this, query);
}
@Override
public <T extends StrolchElement> T findElement(Locator locator) throws StrolchModelException, ClassCastException {
return findElement(locator, false);

View File

@ -1,12 +1,12 @@
/*
* 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.
@ -19,7 +19,6 @@ import java.util.List;
import java.util.Set;
import li.strolch.model.audit.Audit;
import li.strolch.model.query.AuditQuery;
import li.strolch.utils.collections.DateRange;
/**
@ -52,6 +51,4 @@ public interface AuditDao {
void removeAll(List<Audit> audits);
long removeAll(String type, DateRange dateRange);
<U> List<U> doQuery(AuditQuery<U> query);
}

View File

@ -30,18 +30,10 @@ import li.strolch.model.activity.Action;
import li.strolch.model.activity.Activity;
import li.strolch.model.audit.AccessType;
import li.strolch.model.audit.Audit;
import li.strolch.model.audit.AuditVisitor;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.parameter.StringListParameter;
import li.strolch.model.parameter.StringParameter;
import li.strolch.model.policy.PolicyDef;
import li.strolch.model.query.ActivityQuery;
import li.strolch.model.query.AuditQuery;
import li.strolch.model.query.OrderQuery;
import li.strolch.model.query.ResourceQuery;
import li.strolch.model.visitor.ActivityVisitor;
import li.strolch.model.visitor.OrderVisitor;
import li.strolch.model.visitor.ResourceVisitor;
import li.strolch.policy.StrolchPolicy;
import li.strolch.privilege.base.AccessDeniedException;
import li.strolch.privilege.base.PrivilegeException;
@ -236,10 +228,10 @@ public interface StrolchTransaction extends AutoCloseable {
* the element from which to retrieve the {@link PolicyDef
* @param <T>
* the type of policy to return
* @param clazz
* the type of policy to return
*
* @return the policy
* @param clazz
* the type of policy to return
*/
<T extends StrolchPolicy> T getPolicy(PolicyContainer element, Class<T> clazz);
@ -624,60 +616,6 @@ public interface StrolchTransaction extends AutoCloseable {
*/
Audit auditFrom(AccessType accessType, StrolchRootElement element);
/**
* <p>
* Performs the given {@link OrderQuery} and each returned {@link Order} is passed through the {@link OrderVisitor}
* attached to the {@link OrderQuery} and the return value of the visitor is added to the return list
* </p>
*
* @param query
* the query to perform
*
* @return the result list of elements as returned by the {@link OrderVisitor}, never null
*/
<U> List<U> doQuery(OrderQuery<U> query);
/**
* <p>
* Performs the given {@link ResourceQuery} and each returned {@link Resource} is passed through the {@link
* ResourceVisitor} attached to the {@link ResourceQuery} and the return value of the visitor is added to the return
* list
* </p>
*
* @param query
* the query to perform
*
* @return the result list of elements as returned by the {@link ResourceVisitor}, never null
*/
<U> List<U> doQuery(ResourceQuery<U> query);
/**
* <p>
* Performs the given {@link ActivityQuery} and each returned {@link Activity} is passed through the {@link
* ActivityVisitor} attached to the {@link ActivityQuery} and the return value of the visitor is added to the return
* list
* </p>
*
* @param query
* the query to perform
*
* @return the result list of elements as returned by the {@link ActivityVisitor}, never null
*/
<U> List<U> doQuery(ActivityQuery<U> query);
/**
* <p>
* Performs the given {@link AuditQuery} and each returned {@link Audit} is passed through the {@link AuditVisitor}
* attached to the {@link AuditQuery} and the return value of the visitor is added to the return list
* </p>
*
* @param query
* the query to perform
*
* @return the result list of elements as returned by the {@link AuditVisitor}, never null
*/
<U> List<U> doQuery(AuditQuery<U> query);
/**
* <p>
* Used to find a {@link StrolchElement} by a {@link Locator}, throwing exception if the element is not found

View File

@ -1,39 +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.runtime.query.inmemory;
import li.strolch.model.State;
import li.strolch.model.activity.Activity;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ActivityStateSelector implements Selector<Activity> {
private State state;
/**
* @param state
*/
public ActivityStateSelector(State state) {
this.state = state;
}
@Override
public boolean select(Activity element) {
return this.state.equals(element.getState());
}
}

View File

@ -1,37 +0,0 @@
/*
* Copyright 2015 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.runtime.query.inmemory;
import java.util.stream.Stream;
import li.strolch.agent.api.ElementMap;
import li.strolch.model.activity.Activity;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ActivityTypeNavigator extends StrolchTypeNavigator<Activity> {
public ActivityTypeNavigator(String type) {
super(type);
}
@Override
public <U extends ElementMap<Activity>> Stream<Activity> navigate(StrolchTransaction tx, U elementMap) {
return tx.streamActivities(this.type);
}
}

View File

@ -1,53 +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.runtime.query.inmemory;
import java.util.List;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AndSelector<T extends StrolchElement> extends BooleanSelector<T> {
public AndSelector() {
super();
}
public AndSelector(List<Selector<T>> selectors) {
super(selectors);
}
@Override
public AndSelector<T> with(Selector<T> selector) {
super.with(selector);
return this;
}
@Override
public boolean select(T element) {
if (this.selectors == null || this.selectors.isEmpty())
return true;
for (Selector<T> selector : this.selectors) {
if (!selector.select(element))
return false;
}
return true;
}
}

View File

@ -1,29 +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.runtime.query.inmemory;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AnySelector<T extends StrolchElement> implements Selector<T> {
@Override
public boolean select(T element) {
return true;
}
}

View File

@ -1,30 +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.runtime.query.inmemory;
import java.util.List;
import li.strolch.agent.api.AuditTrail;
import li.strolch.model.audit.Audit;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface AuditNavigator {
public List<Audit> navigate(StrolchTransaction tx, AuditTrail auditTrail);
}

View File

@ -1,134 +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.runtime.query.inmemory;
import java.util.HashSet;
import java.util.Set;
import li.strolch.model.audit.AccessType;
import li.strolch.model.audit.Audit;
import li.strolch.model.query.ActionSelection;
import li.strolch.model.query.ElementSelection;
import li.strolch.model.query.IdentitySelection;
import li.strolch.model.query.StringSelection;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AuditSelector {
public abstract boolean select(Audit audit);
public static AuditSelector selectorFor(ElementSelection selection) {
return new ElementSelector(selection);
}
public static AuditSelector selectorFor(IdentitySelection selection) {
return new IdentitySelector(selection);
}
public static AuditSelector selectorFor(ActionSelection selection) {
return new ActionSelector(selection);
}
private static class ElementSelector extends AuditSelector {
private StringSelection elementSubTypeSelection;
private StringSelection elementAccessedSelection;
public ElementSelector(ElementSelection selection) {
this.elementSubTypeSelection = selection.getElementSubTypeSelection();
this.elementAccessedSelection = selection.getElementAccessedSelection();
}
@Override
public boolean select(Audit audit) {
if (this.elementSubTypeSelection != null) {
if (!this.elementSubTypeSelection.matches(audit.getElementSubType()))
return false;
}
if (this.elementAccessedSelection != null) {
if (!this.elementAccessedSelection.matches(audit.getElementAccessed()))
return false;
}
return true;
}
}
public static class IdentitySelector extends AuditSelector {
private StringSelection firstnameSelection;
private StringSelection lastnameSelection;
private StringSelection usernameSelection;
public IdentitySelector(IdentitySelection selection) {
this.firstnameSelection = selection.getFirstnameSelection();
this.lastnameSelection = selection.getLastnameSelection();
this.usernameSelection = selection.getUsernameSelection();
}
@Override
public boolean select(Audit audit) {
if (this.firstnameSelection != null) {
if (!this.firstnameSelection.matches(audit.getFirstname()))
return false;
}
if (this.lastnameSelection != null) {
if (!this.lastnameSelection.matches(audit.getLastname()))
return false;
}
if (this.usernameSelection != null) {
if (!this.usernameSelection.matches(audit.getUsername()))
return false;
}
return true;
}
}
public static class ActionSelector extends AuditSelector {
private Set<AccessType> accessTypes;
private StringSelection actionSelection;
public ActionSelector(ActionSelection selection) {
if (selection.getAccessTypes() != null && !selection.getAccessTypes().isEmpty())
this.accessTypes = new HashSet<>(selection.getAccessTypes());
this.actionSelection = selection.getActionSelection();
}
@Override
public boolean select(Audit audit) {
if (this.accessTypes != null) {
if (!this.accessTypes.contains(audit.getAccessType()))
return false;
}
if (this.actionSelection != null) {
if (!this.actionSelection.matches(audit.getAction()))
return false;
}
return true;
}
}
}

View File

@ -1,45 +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.runtime.query.inmemory;
import java.util.List;
import li.strolch.agent.api.AuditTrail;
import li.strolch.model.audit.Audit;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.collections.DateRange;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditTypeNavigator implements AuditNavigator {
private String type;
private DateRange dateRange;
public AuditTypeNavigator(String type, DateRange dateRange) {
DBC.PRE.assertNotNull("type", type);
DBC.PRE.assertNotNull("dateRange", dateRange);
this.type = type;
this.dateRange = dateRange;
}
@Override
public List<Audit> navigate(StrolchTransaction tx, AuditTrail auditTrail) {
return auditTrail.getAllElements(tx, this.type, this.dateRange);
}
}

View File

@ -1,56 +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.runtime.query.inmemory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class BooleanSelector<T extends StrolchElement> implements Selector<T> {
protected List<Selector<T>> selectors;
public BooleanSelector() {
this.selectors = new ArrayList<>(1);
}
public BooleanSelector(Selector<T> selector) {
this.selectors = Arrays.asList(selector);
}
public BooleanSelector(Selector<T> leftHandSide, Selector<T> rightHandSide) {
this.selectors = new ArrayList<>(2);
this.selectors.add(leftHandSide);
this.selectors.add(rightHandSide);
}
public BooleanSelector(List<Selector<T>> selectors) {
this.selectors = selectors;
}
public BooleanSelector<T> with(Selector<T> selector) {
this.selectors.add(selector);
return this;
}
@Override
public abstract boolean select(T element);
}

View File

@ -1,43 +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.runtime.query.inmemory;
import li.strolch.model.Order;
import li.strolch.utils.collections.DateRange;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class DateSelector implements Selector<Order> {
private DateRange dateRange;
public DateSelector(DateRange dateRange) {
this.dateRange = dateRange;
}
/**
* @return the dateRange
*/
public DateRange getDateRange() {
return this.dateRange;
}
@Override
public boolean select(Order element) {
return this.dateRange.contains(element.getDate());
}
}

View File

@ -1,79 +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.runtime.query.inmemory;
import java.util.List;
import li.strolch.model.StrolchElement;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class IdSelector<T extends StrolchElement> implements Selector<T> {
private StringMatchMode matchMode;
private List<String> ids;
/**
* @param ids
* @param matchMode
*/
public IdSelector(List<String> ids, StringMatchMode matchMode) {
this.ids = ids;
this.matchMode = matchMode;
}
/**
* @return the ids
*/
public List<String> getIds() {
return this.ids;
}
/**
* @return the matchMode
*/
public StringMatchMode getMatchMode() {
return this.matchMode;
}
/**
* @param id
* @return
*/
public IdSelector<T> with(String id) {
this.ids.add(id);
return this;
}
@Override
public boolean select(StrolchElement element) {
if (this.ids.isEmpty())
return true;
String elemId = element.getId();
if (this.ids.size() == 1)
return this.matchMode.matches(elemId, this.ids.get(0));
for (String id : this.ids) {
if (this.matchMode.matches(elemId, id))
return true;
}
return false;
}
}

View File

@ -1,71 +0,0 @@
/*
* Copyright 2015 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.runtime.query.inmemory;
import java.util.List;
import li.strolch.model.activity.Activity;
import li.strolch.model.query.ActivityQuery;
import li.strolch.model.query.ActivityQueryVisitor;
import li.strolch.model.query.ActivityStateSelection;
import li.strolch.model.query.StrolchTypeNavigation;
import li.strolch.model.visitor.ActivityVisitor;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InMemoryActivityQueryVisitor extends InMemoryQueryVisitor<Activity> implements ActivityQueryVisitor {
public InMemoryActivityQueryVisitor() {
super();
}
@Override
protected InMemoryQueryVisitor<Activity> newInstance() {
return new InMemoryActivityQueryVisitor();
}
public <U> InMemoryQuery<Activity, U> visit(ActivityQuery<U> activityQuery) {
ActivityVisitor<U> activityVisitor = activityQuery.getVisitor();
DBC.PRE.assertNotNull("ActivityVisitor may not be null!", activityVisitor); //$NON-NLS-1$
activityQuery.accept(this);
Navigator<Activity> navigator = getNavigator();
if (navigator == null) {
String msg = "Query is missing a navigation!"; //$NON-NLS-1$
throw new QueryException(msg);
}
List<Selector<Activity>> selectors = getSelectors();
if (selectors.isEmpty())
return new InMemoryQuery<>(navigator, null, activityVisitor, getComparator());
DBC.PRE.assertTrue("Invalid query as it may only contain one selector!", selectors.size() == 1); //$NON-NLS-1$
return new InMemoryQuery<>(navigator, selectors.get(0), activityVisitor, getComparator());
}
@Override
public void visit(StrolchTypeNavigation navigation) {
setNavigator(new ActivityTypeNavigator(navigation.getType()));
}
@Override
public void visit(ActivityStateSelection selection) {
addSelector(new ActivityStateSelector(selection.getState()));
}
}

View File

@ -1,82 +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.runtime.query.inmemory;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.AuditTrail;
import li.strolch.model.audit.Audit;
import li.strolch.model.audit.AuditVisitor;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.dbc.DBC;
/**
* @param <U>
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InMemoryAuditQuery<U> {
private AuditTypeNavigator navigator;
private List<AuditSelector> selectors;
private AuditVisitor<U> auditVisitor;
private long limit;
public InMemoryAuditQuery(AuditTypeNavigator navigator, long limit, List<AuditSelector> selectors,
AuditVisitor<U> auditVisitor) {
DBC.PRE.assertNotNull("Navigator must be set!", navigator); //$NON-NLS-1$
DBC.PRE.assertNotNull("selectors must be set!", selectors); //$NON-NLS-1$
DBC.PRE.assertNotNull("auditVisitor must be set!", auditVisitor); //$NON-NLS-1$
this.navigator = navigator;
this.limit = limit;
this.selectors = selectors;
this.auditVisitor = auditVisitor;
}
public List<U> doQuery(StrolchTransaction tx, AuditTrail auditTrail) {
List<U> result = new ArrayList<>();
List<Audit> elements = this.navigator.navigate(tx, auditTrail);
elements.sort((a1, a2) -> a2.getDate().compareTo(a1.getDate()));
for (Audit audit : elements) {
if (!this.selectors.isEmpty()) {
boolean nok = false;
for (AuditSelector selector : this.selectors) {
if (!selector.select(audit)) {
nok = true;
break;
}
}
if (nok)
continue;
}
U returnValue = this.auditVisitor.visitAudit(audit);
DBC.INTERIM.assertNotNull("Visitor may not return null in query!", returnValue); //$NON-NLS-1$
result.add(returnValue);
if (this.limit > 0 && result.size() >= this.limit)
break;
}
return result;
}
}

View File

@ -1,72 +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.runtime.query.inmemory;
import java.util.ArrayList;
import java.util.List;
import li.strolch.model.audit.AuditVisitor;
import li.strolch.model.query.*;
import li.strolch.utils.collections.DateRange;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InMemoryAuditQueryVisitor<U> implements AuditQueryVisitor {
private AuditTypeNavigator navigator;
private List<AuditSelector> selectors;
public InMemoryAuditQuery<U> toInMemory(AuditQuery<U> auditQuery) {
AuditVisitor<U> auditVisitor = auditQuery.getVisitor();
DBC.PRE.assertNotNull("auditVisitor", auditVisitor); //$NON-NLS-1$
this.selectors = new ArrayList<>();
auditQuery.accept(this);
if (this.navigator == null) {
String msg = "Query is missing a navigation!"; //$NON-NLS-1$
throw new QueryException(msg);
}
long limit = auditQuery.getLimit();
return new InMemoryAuditQuery<>(this.navigator, limit, this.selectors, auditVisitor);
}
@Override
public void visit(ElementSelection selection) {
this.selectors.add(AuditSelector.selectorFor(selection));
}
@Override
public void visit(IdentitySelection selection) {
this.selectors.add(AuditSelector.selectorFor(selection));
}
@Override
public void visit(ActionSelection selection) {
this.selectors.add(AuditSelector.selectorFor(selection));
}
@Override
public void visit(AuditQuery<?> auditQuery) {
String type = auditQuery.getElementTypeSelection();
DateRange dateRange = auditQuery.getDateRange();
this.navigator = new AuditTypeNavigator(type, dateRange);
}
}

View File

@ -1,77 +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.runtime.query.inmemory;
import java.util.List;
import li.strolch.model.Order;
import li.strolch.model.query.DateSelection;
import li.strolch.model.query.OrderQuery;
import li.strolch.model.query.OrderQueryVisitor;
import li.strolch.model.query.OrderStateSelection;
import li.strolch.model.query.StrolchTypeNavigation;
import li.strolch.model.visitor.OrderVisitor;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order> implements OrderQueryVisitor {
public InMemoryOrderQueryVisitor() {
super();
}
@Override
protected InMemoryQueryVisitor<Order> newInstance() {
return new InMemoryOrderQueryVisitor();
}
public <U> InMemoryQuery<Order, U> visit(OrderQuery<U> orderQuery) {
OrderVisitor<U> orderVisitor = orderQuery.getVisitor();
DBC.PRE.assertNotNull("OrderVisitor may not be null!", orderVisitor); //$NON-NLS-1$
orderQuery.accept(this);
Navigator<Order> navigator = getNavigator();
if (navigator == null) {
String msg = "Query is missing a navigation!"; //$NON-NLS-1$
throw new QueryException(msg);
}
List<Selector<Order>> selectors = getSelectors();
if (selectors.isEmpty())
return new InMemoryQuery<>(navigator, null, orderVisitor, getComparator());
DBC.PRE.assertTrue("Invalid query as it may only contain one selector!", selectors.size() == 1); //$NON-NLS-1$
return new InMemoryQuery<>(navigator, selectors.get(0), orderVisitor, getComparator());
}
@Override
public void visit(StrolchTypeNavigation navigation) {
setNavigator(new OrderTypeNavigator(navigation.getType()));
}
@Override
public void visit(DateSelection selection) {
addSelector(new DateSelector(selection.getDateRange()));
}
@Override
public void visit(OrderStateSelection selection) {
addSelector(new OrderStateSelector(selection.getState()));
}
}

View File

@ -1,93 +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.runtime.query.inmemory;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import li.strolch.agent.api.ElementMap;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.visitor.StrolchElementVisitor;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InMemoryQuery<T extends StrolchRootElement, U> {
private Navigator<T> navigator;
private Selector<T> selector;
private StrolchElementVisitor<U> elementVisitor;
private Comparator<T> comparator;
public InMemoryQuery(Navigator<T> navigator, Selector<T> selector, StrolchElementVisitor<U> elementVisitor,
Comparator<T> comparator) {
this.navigator = navigator;
this.selector = selector;
this.elementVisitor = elementVisitor;
this.comparator = comparator;
}
/**
* @param navigator
* the navigator to set
*/
public void setNavigator(Navigator<T> navigator) {
this.navigator = navigator;
}
/**
* @param selector
* the selector to set
*/
public void setSelector(Selector<T> selector) {
this.selector = selector;
}
/**
* @param elementVisitor
* the elementVisitor to set
*/
public void setElementVisitor(StrolchElementVisitor<U> elementVisitor) {
this.elementVisitor = elementVisitor;
}
public List<U> doQuery(StrolchTransaction tx, ElementMap<T> elementMap) {
if (this.selector == null)
return Collections.emptyList();
Stream<T> elements = this.navigator.navigate(tx, elementMap);
if (this.comparator != null)
elements = elements.sorted(this.comparator);
return elements.filter(element -> this.selector.select(element)).map(element -> {
U returnValue = element.accept(this.elementVisitor);
DBC.INTERIM.assertNotNull("Visitor may not return null in query!", returnValue); //$NON-NLS-1$
if (returnValue instanceof StrolchRootElement) {
@SuppressWarnings("unchecked")
U ret = (U) ((StrolchRootElement) returnValue).getClone(true);
returnValue = ret;
}
return returnValue;
}).collect(Collectors.toList());
}
}

View File

@ -1,279 +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.runtime.query.inmemory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.query.AndSelection;
import li.strolch.model.query.BooleanSelection;
import li.strolch.model.query.IdSelection;
import li.strolch.model.query.NameSelection;
import li.strolch.model.query.NotSelection;
import li.strolch.model.query.OrSelection;
import li.strolch.model.query.ParameterBagSelection;
import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection;
import li.strolch.model.query.ParameterSelection.AnyTypeParameterSelection;
import li.strolch.model.query.ParameterSelection.BooleanParameterSelection;
import li.strolch.model.query.ParameterSelection.DateParameterSelection;
import li.strolch.model.query.ParameterSelection.DateRangeParameterSelection;
import li.strolch.model.query.ParameterSelection.DurationParameterSelection;
import li.strolch.model.query.ParameterSelection.FloatListParameterSelection;
import li.strolch.model.query.ParameterSelection.FloatParameterSelection;
import li.strolch.model.query.ParameterSelection.IntegerListParameterSelection;
import li.strolch.model.query.ParameterSelection.IntegerParameterSelection;
import li.strolch.model.query.ParameterSelection.LongListParameterSelection;
import li.strolch.model.query.ParameterSelection.LongParameterSelection;
import li.strolch.model.query.ParameterSelection.NullParameterSelection;
import li.strolch.model.query.ParameterSelection.StringListParameterSelection;
import li.strolch.model.query.ParameterSelection.StringParameterSelection;
import li.strolch.model.query.ParameterSelectionVisitor;
import li.strolch.model.query.Selection;
import li.strolch.model.query.StrolchRootElementSelectionVisitor;
import li.strolch.model.query.ordering.OrderById;
import li.strolch.model.query.ordering.OrderByName;
import li.strolch.model.query.ordering.OrderByParameter;
import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
import li.strolch.runtime.query.inmemory.ParameterBagSelector.NullParameterBagSelector;
import li.strolch.runtime.query.inmemory.ParameterSelector.StringParameterSelector;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class InMemoryQueryVisitor<T extends StrolchRootElement>
implements StrolchRootElementSelectionVisitor, ParameterSelectionVisitor, StrolchQueryOrderingVisitor {
private Navigator<T> navigator;
private Comparator<T> comparator;
private List<Selector<T>> selectors;
private boolean any;
public InMemoryQueryVisitor() {
this.selectors = new ArrayList<>();
}
public List<Selector<T>> getSelectors() {
return Collections.unmodifiableList(this.selectors);
}
public Navigator<T> getNavigator() {
return this.navigator;
}
public Comparator<T> getComparator() {
return this.comparator;
}
/**
* @param navigator
*/
protected void setNavigator(StrolchTypeNavigator<T> navigator) {
this.navigator = navigator;
}
/**
* Returns a new instance of this concrete type for performing recursive {@link BooleanSelection BooleanSelections}
*
* @return a new instance of this concrete type
*/
protected abstract InMemoryQueryVisitor<T> newInstance();
private void assertNotAny() {
DBC.INTERIM.assertFalse("Not allowed to use further Selections with Any!", this.any); //$NON-NLS-1$
}
protected void addSelector(Selector<T> selector) {
assertNotAny();
this.selectors.add(selector);
}
@Override
public void visitAny() {
DBC.PRE.assertEmpty("Only one selection allowed when using Any!", this.selectors); //$NON-NLS-1$
addSelector(new AnySelector<T>());
this.any = true;
}
@Override
public void visitAnd(AndSelection andSelection) {
assertNotAny();
InMemoryQueryVisitor<T> query = newInstance();
List<Selection> selections = andSelection.getSelections();
for (Selection selection : selections) {
selection.accept(query);
}
AndSelector<T> andSelector = new AndSelector<>(query.getSelectors());
addSelector(andSelector);
}
@Override
public void visitOr(OrSelection orSelection) {
assertNotAny();
InMemoryQueryVisitor<T> query = newInstance();
List<Selection> selections = orSelection.getSelections();
for (Selection selection : selections) {
selection.accept(query);
}
OrSelector<T> orSelector = new OrSelector<>(query.getSelectors());
addSelector(orSelector);
}
@Override
public void visitNot(NotSelection notSelection) {
assertNotAny();
InMemoryQueryVisitor<T> query = newInstance();
List<Selection> selections = notSelection.getSelections();
for (Selection selection : selections) {
selection.accept(query);
}
List<Selector<T>> notSelectors = query.getSelectors();
if (!notSelectors.isEmpty()) {
NotSelector<T> notSelector = new NotSelector<>(notSelectors.get(0));
addSelector(notSelector);
}
}
@Override
public void visit(IdSelection selection) {
addSelector(new IdSelector<T>(selection.getIds(), selection.getMatchMode()));
}
@Override
public void visit(NameSelection selection) {
addSelector(new NameSelector<T>(selection.getName(), selection.getMatchMode()));
}
@Override
public void visit(StringParameterSelection selection) {
StringParameterSelector<T> stringSelector = //
ParameterSelector.<T> stringSelector( //
selection.getBagKey(), //
selection.getParamKey(), //
selection.getValue(), //
selection.getMatchMode());
addSelector(stringSelector);
}
@Override
public void visit(IntegerParameterSelection selection) {
addSelector(ParameterSelector.<T> integerSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(BooleanParameterSelection selection) {
addSelector(ParameterSelector.<T> booleanSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(LongParameterSelection selection) {
addSelector(ParameterSelector.<T> longSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(FloatParameterSelection selection) {
addSelector(ParameterSelector.<T> floatSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(DateParameterSelection selection) {
addSelector(ParameterSelector.<T> dateSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(DurationParameterSelection selection) {
addSelector(ParameterSelector.<T> durationSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(DateRangeParameterSelection selection) {
addSelector(ParameterSelector.<T> dateRangeSelector(selection.getBagKey(), selection.getParamKey(),
selection.getDateRange()));
}
@Override
public void visit(StringListParameterSelection selection) {
addSelector(ParameterSelector.<T> stringListSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(IntegerListParameterSelection selection) {
addSelector(ParameterSelector.<T> integerListSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(FloatListParameterSelection selection) {
addSelector(ParameterSelector.<T> floatListSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(LongListParameterSelection selection) {
addSelector(ParameterSelector.<T> longListSelector(selection.getBagKey(), selection.getParamKey(),
selection.getValue()));
}
@Override
public void visit(NullParameterSelection selection) {
addSelector(ParameterSelector.<T> nullSelector(selection.getBagKey(), selection.getParamKey()));
}
@Override
public void visit(NullParameterBagSelection selection) {
addSelector(new NullParameterBagSelector<T>(selection.getBagKey()));
}
@Override
public void visit(ParameterBagSelection selection) {
addSelector(new ParameterBagSelector<T>(selection.getBagKey()));
}
@Override
public void visit(AnyTypeParameterSelection selection) {
addSelector(ParameterSelector.<T> anyTypeSelection(selection.getBagKey(), selection.getParamKey(),
selection.getValue(), selection.getMatchMode()));
}
@Override
public InMemoryQueryVisitor<T> visit(OrderById ordering) {
this.comparator = new InMemoryStrolchQueryOrderingVisitor<T>().visit(ordering).getComparator();
return this;
}
@Override
public InMemoryQueryVisitor<T> visit(OrderByName ordering) {
this.comparator = new InMemoryStrolchQueryOrderingVisitor<T>().visit(ordering).getComparator();
return this;
}
@Override
public InMemoryQueryVisitor<T> visit(OrderByParameter ordering) {
this.comparator = new InMemoryStrolchQueryOrderingVisitor<T>().visit(ordering).getComparator();
return this;
}
}

View File

@ -1,66 +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.runtime.query.inmemory;
import java.util.List;
import li.strolch.model.Resource;
import li.strolch.model.query.ResourceQuery;
import li.strolch.model.query.ResourceQueryVisitor;
import li.strolch.model.query.StrolchTypeNavigation;
import li.strolch.model.visitor.ResourceVisitor;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor<Resource>
implements ResourceQueryVisitor {
public InMemoryResourceQueryVisitor() {
super();
}
@Override
protected InMemoryQueryVisitor<Resource> newInstance() {
return new InMemoryResourceQueryVisitor();
}
public <U> InMemoryQuery<Resource, U> visit(ResourceQuery<U> resourceQuery) {
ResourceVisitor<U> resourceVisitor = resourceQuery.getVisitor();
DBC.PRE.assertNotNull("ResourceVisitor may not be null!", resourceVisitor); //$NON-NLS-1$
resourceQuery.accept(this);
Navigator<Resource> navigator = getNavigator();
if (navigator == null) {
String msg = "Query is missing a navigation!"; //$NON-NLS-1$
throw new QueryException(msg);
}
List<Selector<Resource>> selectors = getSelectors();
if (selectors.isEmpty())
return new InMemoryQuery<>(navigator, null, resourceVisitor, getComparator());
DBC.INTERIM.assertTrue("Invalid query as it may only contain one selector!", selectors.size() == 1); //$NON-NLS-1$
return new InMemoryQuery<>(navigator, selectors.get(0), resourceVisitor, getComparator());
}
@Override
public void visit(StrolchTypeNavigation navigation) {
setNavigator(new ResourceTypeNavigator(navigation.getType()));
}
}

View File

@ -1,57 +0,0 @@
/*
* Copyright 2015 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.runtime.query.inmemory;
import java.util.Comparator;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.query.ordering.ByIdComparator;
import li.strolch.model.query.ordering.ByNameComparator;
import li.strolch.model.query.ordering.ByParamComparator;
import li.strolch.model.query.ordering.OrderById;
import li.strolch.model.query.ordering.OrderByName;
import li.strolch.model.query.ordering.OrderByParameter;
import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InMemoryStrolchQueryOrderingVisitor<T extends StrolchRootElement> implements StrolchQueryOrderingVisitor {
private Comparator<T> comparator;
public Comparator<T> getComparator() {
return this.comparator;
}
@Override
public InMemoryStrolchQueryOrderingVisitor<T> visit(OrderById ordering) {
this.comparator = new ByIdComparator<>(ordering.isAscending());
return this;
}
@Override
public InMemoryStrolchQueryOrderingVisitor<T> visit(OrderByName ordering) {
this.comparator = new ByNameComparator<>(ordering.isAscending());
return this;
}
@Override
public InMemoryStrolchQueryOrderingVisitor<T> visit(OrderByParameter ordering) {
this.comparator = new ByParamComparator<>(ordering.getBagKey(), ordering.getParamKey(), ordering.isAscending());
return this;
}
}

View File

@ -1,46 +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.runtime.query.inmemory;
import li.strolch.model.StrolchElement;
import li.strolch.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NameSelector<T extends StrolchElement> implements Selector<T> {
private StringMatchMode matchMode;
private String name;
public NameSelector(String name, StringMatchMode matchMode) {
this.name = name;
this.matchMode = matchMode;
}
@Override
public boolean select(T element) {
String name = element.getName();
return this.matchMode.matches(name, this.name);
}
/**
* @return the matchMode
*/
public StringMatchMode getMatchMode() {
return this.matchMode;
}
}

View File

@ -1,30 +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.runtime.query.inmemory;
import java.util.stream.Stream;
import li.strolch.agent.api.ElementMap;
import li.strolch.model.StrolchRootElement;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface Navigator<T extends StrolchRootElement> {
public <U extends ElementMap<T>> Stream<T> navigate(StrolchTransaction tx, U elementMap);
}

View File

@ -1,49 +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.runtime.query.inmemory;
import li.strolch.model.StrolchElement;
import li.strolch.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NotSelector<T extends StrolchElement> extends BooleanSelector<T> {
/**
* @param selector
*/
NotSelector(Selector<T> selector) {
super(selector);
}
/**
* @throws UnsupportedOperationException
* because a {@link NotSelector} can only work on a single {@link Selector}
*/
@Override
public NotSelector<T> with(Selector<T> selector) {
throw new UnsupportedOperationException("NotSelector can only have a single Selector"); //$NON-NLS-1$
}
@Override
public boolean select(T element) {
if (this.selectors == null || this.selectors.isEmpty())
return true;
DBC.PRE.assertTrue("Only one selector allowed!", this.selectors.size() == 1); //$NON-NLS-1$
return !this.selectors.get(0).select(element);
}
}

View File

@ -1,53 +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.runtime.query.inmemory;
import java.util.List;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrSelector<T extends StrolchElement> extends BooleanSelector<T> {
public OrSelector() {
super();
}
public OrSelector(List<Selector<T>> selectors) {
super(selectors);
}
@Override
public OrSelector<T> with(Selector<T> selector) {
super.with(selector);
return this;
}
@Override
public boolean select(T element) {
if (this.selectors == null || this.selectors.isEmpty())
return true;
for (Selector<T> selector : this.selectors) {
if (selector.select(element))
return true;
}
return false;
}
}

View File

@ -1,39 +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.runtime.query.inmemory;
import li.strolch.model.Order;
import li.strolch.model.State;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderStateSelector implements Selector<Order> {
private State state;
/**
* @param state
*/
public OrderStateSelector(State state) {
this.state = state;
}
@Override
public boolean select(Order element) {
return this.state.equals(element.getState());
}
}

View File

@ -1,37 +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.runtime.query.inmemory;
import java.util.stream.Stream;
import li.strolch.agent.api.ElementMap;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderTypeNavigator extends StrolchTypeNavigator<Order> {
public OrderTypeNavigator(String type) {
super(type);
}
@Override
public <U extends ElementMap<Order>> Stream<Order> navigate(StrolchTransaction tx, U elementMap) {
return tx.streamOrders(this.type);
}
}

View File

@ -1,47 +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.runtime.query.inmemory;
import li.strolch.model.StrolchRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ParameterBagSelector<T extends StrolchRootElement> implements Selector<T> {
protected String bagKey;
public ParameterBagSelector(String bagKey) {
this.bagKey = bagKey;
}
@Override
public boolean select(T element) {
return element.hasParameterBag(this.bagKey);
}
public static class NullParameterBagSelector<T extends StrolchRootElement> extends ParameterBagSelector<T> {
public NullParameterBagSelector(String bagKey) {
super(bagKey);
}
@Override
public boolean select(T element) {
return !element.hasParameterBag(this.bagKey);
}
}
}

View File

@ -1,417 +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.runtime.query.inmemory;
import java.util.Date;
import java.util.List;
import li.strolch.model.ParameterBag;
import li.strolch.model.ParameterBagContainer;
import li.strolch.model.parameter.BooleanParameter;
import li.strolch.model.parameter.DateParameter;
import li.strolch.model.parameter.DurationParameter;
import li.strolch.model.parameter.FloatParameter;
import li.strolch.model.parameter.IntegerParameter;
import li.strolch.model.parameter.ListParameter;
import li.strolch.model.parameter.LongParameter;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.parameter.StringParameter;
import li.strolch.utils.StringMatchMode;
import li.strolch.utils.collections.DateRange;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class ParameterSelector<T extends ParameterBagContainer> implements Selector<T> {
protected String bagKey;
protected String paramKey;
public ParameterSelector(String bagKey, String key) {
this.bagKey = bagKey;
this.paramKey = key;
}
@Override
public abstract boolean select(ParameterBagContainer element);
public static <T extends ParameterBagContainer> StringParameterSelector<T> stringSelector(String bagKey,
String paramKey, String value, StringMatchMode matchMode) {
return new StringParameterSelector<>(bagKey, paramKey, value, matchMode);
}
public static <T extends ParameterBagContainer> IntegerParameterSelector<T> integerSelector(String bagKey,
String paramKey, int value) {
return new IntegerParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> BooleanParameterSelector<T> booleanSelector(String bagKey,
String paramKey, boolean value) {
return new BooleanParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> FloatParameterSelector<T> floatSelector(String bagKey,
String paramKey, double value) {
return new FloatParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> LongParameterSelector<T> longSelector(String bagKey,
String paramKey, long value) {
return new LongParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> DateParameterSelector<T> dateSelector(String bagKey,
String paramKey, Date value) {
return new DateParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> DurationParameterSelector<T> durationSelector(String bagKey,
String paramKey, Long value) {
return new DurationParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> DateRangeParameterSelector<T> dateRangeSelector(String bagKey,
String paramKey, DateRange dateRange) {
return new DateRangeParameterSelector<>(bagKey, paramKey, dateRange);
}
public static <T extends ParameterBagContainer> StringListParameterSelector<T> stringListSelector(String bagKey,
String paramKey, List<String> value) {
return new StringListParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> IntegerListParameterSelector<T> integerListSelector(String bagKey,
String paramKey, List<Integer> value) {
return new IntegerListParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> FloatListParameterSelector<T> floatListSelector(String bagKey,
String paramKey, List<Double> value) {
return new FloatListParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> LongListParameterSelector<T> longListSelector(String bagKey,
String paramKey, List<Long> value) {
return new LongListParameterSelector<>(bagKey, paramKey, value);
}
public static <T extends ParameterBagContainer> NullParameterSelector<T> nullSelector(String bagKey,
String paramKey) {
return new NullParameterSelector<>(bagKey, paramKey);
}
public static <T extends ParameterBagContainer> AnyTypeParameterSelector<T> anyTypeSelection(String bagKey,
String paramKey, String value, StringMatchMode matchMode) {
return new AnyTypeParameterSelector<>(bagKey, paramKey, value, matchMode);
}
public static class AnyTypeParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private StringMatchMode matchMode;
private String value;
public AnyTypeParameterSelector(String bagKey, String key, String value, StringMatchMode matchMode) {
super(bagKey, key);
this.value = value;
this.matchMode = matchMode;
}
@Override
public boolean select(ParameterBagContainer element) {
ParameterBag bag = element.getParameterBag(this.bagKey);
if (bag == null) {
return false;
}
Parameter<?> parameter = bag.getParameter(this.paramKey);
if (parameter == null)
return false;
String valueAsString = parameter.getValueAsString();
return this.matchMode.matches(valueAsString, this.value);
}
}
public static class NullParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
public NullParameterSelector(String bagKey, String key) {
super(bagKey, key);
}
@Override
public boolean select(ParameterBagContainer element) {
ParameterBag bag = element.getParameterBag(this.bagKey);
if (bag == null) {
return false;
}
return !bag.hasParameter(this.paramKey);
}
}
public static class StringParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private StringMatchMode matchMode;
private String value;
public StringParameterSelector(String bagKey, String paramKey, String value, StringMatchMode matchMode) {
super(bagKey, paramKey);
this.value = value;
this.matchMode = matchMode;
}
public StringMatchMode getMatchMode() {
return this.matchMode;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
StringParameter param = bag.getParameter(this.paramKey);
String paramValue = param.getValue();
return this.matchMode.matches(paramValue, this.value);
}
}
public static class IntegerParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private Integer value;
public IntegerParameterSelector(String bagKey, String paramKey, Integer value) {
super(bagKey, paramKey);
this.value = value;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
IntegerParameter param = bag.getParameter(this.paramKey);
return param.getValue().equals(this.value);
}
}
public static class BooleanParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private Boolean value;
public BooleanParameterSelector(String bagKey, String paramKey, Boolean value) {
super(bagKey, paramKey);
this.value = value;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
BooleanParameter param = bag.getParameter(this.paramKey);
return param.getValue().equals(this.value);
}
}
public static class FloatParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private Double value;
public FloatParameterSelector(String bagKey, String paramKey, Double value) {
super(bagKey, paramKey);
this.value = value;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
FloatParameter param = bag.getParameter(this.paramKey);
return param.getValue().equals(this.value);
}
}
public static class LongParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private Long value;
public LongParameterSelector(String bagKey, String paramKey, Long value) {
super(bagKey, paramKey);
this.value = value;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
LongParameter param = bag.getParameter(this.paramKey);
return param.getValue().equals(this.value);
}
}
public static class DateParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private Date value;
public DateParameterSelector(String bagKey, String paramKey, Date value) {
super(bagKey, paramKey);
this.value = value;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
DateParameter param = bag.getParameter(this.paramKey);
return param.getValue().equals(this.value);
}
}
public static class DateRangeParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private DateRange dateRange;
public DateRangeParameterSelector(String bagKey, String paramKey, DateRange dateRange) {
super(bagKey, paramKey);
this.dateRange = dateRange;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
DateParameter param = bag.getParameter(this.paramKey);
Date value = param.getValue();
return this.dateRange.contains(value);
}
}
public static class DurationParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
private Long value;
public DurationParameterSelector(String bagKey, String paramKey, Long value) {
super(bagKey, paramKey);
this.value = value;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
DurationParameter param = bag.getParameter(this.paramKey);
return param.getValue().equals(this.value);
}
}
public static abstract class AbstractListParameterSelector<U, T extends ParameterBagContainer>
extends ParameterSelector<T> {
private List<U> value;
public AbstractListParameterSelector(String bagKey, String paramKey, List<U> value) {
super(bagKey, paramKey);
this.value = value;
}
@Override
public boolean select(ParameterBagContainer element) {
if (!element.hasParameterBag(this.bagKey))
return false;
ParameterBag bag = element.getParameterBag(this.bagKey);
if (!bag.hasParameter(this.paramKey))
return false;
ListParameter<U> param = bag.getParameter(this.paramKey);
return param.getValue().containsAll(this.value);
}
}
public static class StringListParameterSelector<T extends ParameterBagContainer>
extends AbstractListParameterSelector<String, T> {
public StringListParameterSelector(String bagKey, String paramKey, List<String> value) {
super(bagKey, paramKey, value);
}
}
public static class IntegerListParameterSelector<T extends ParameterBagContainer>
extends AbstractListParameterSelector<Integer, T> {
public IntegerListParameterSelector(String bagKey, String paramKey, List<Integer> value) {
super(bagKey, paramKey, value);
}
}
public static class FloatListParameterSelector<T extends ParameterBagContainer>
extends AbstractListParameterSelector<Double, T> {
public FloatListParameterSelector(String bagKey, String paramKey, List<Double> value) {
super(bagKey, paramKey, value);
}
}
public static class LongListParameterSelector<T extends ParameterBagContainer>
extends AbstractListParameterSelector<Long, T> {
public LongListParameterSelector(String bagKey, String paramKey, List<Long> value) {
super(bagKey, paramKey, value);
}
}
}

View File

@ -1,35 +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.runtime.query.inmemory;
import li.strolch.exception.StrolchException;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class QueryException extends StrolchException {
public QueryException(String message, Throwable cause) {
super(message, cause);
}
public QueryException(String message) {
super(message);
}
}

View File

@ -1,37 +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.runtime.query.inmemory;
import java.util.stream.Stream;
import li.strolch.agent.api.ElementMap;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ResourceTypeNavigator extends StrolchTypeNavigator<Resource> {
public ResourceTypeNavigator(String type) {
super(type);
}
@Override
public <U extends ElementMap<Resource>> Stream<Resource> navigate(StrolchTransaction tx, U elementMap) {
return tx.streamResources(this.type);
}
}

View File

@ -1,27 +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.runtime.query.inmemory;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface Selector<T extends StrolchElement> {
public boolean select(T element);
}

View File

@ -1,34 +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.runtime.query.inmemory;
import li.strolch.model.StrolchRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class StrolchTypeNavigator<T extends StrolchRootElement> implements Navigator<T> {
protected String type;
public StrolchTypeNavigator(String type) {
this.type = type;
}
public String getType() {
return this.type;
}
}

View File

@ -1,266 +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.runtime.query.inmemory;
import static li.strolch.agent.ComponentContainerTest.PATH_REALM_CONTAINER;
import static org.junit.Assert.assertEquals;
import java.sql.SQLException;
import java.util.*;
import li.strolch.RuntimeMock;
import li.strolch.agent.api.StrolchAgent;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Tags;
import li.strolch.model.audit.AccessType;
import li.strolch.model.audit.Audit;
import li.strolch.model.audit.AuditVisitor;
import li.strolch.model.audit.NoStrategyAuditVisitor;
import li.strolch.model.query.AuditQuery;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.privilege.model.Certificate;
import li.strolch.runtime.StrolchConstants;
import li.strolch.runtime.privilege.PrivilegeHandler;
import li.strolch.utils.StringMatchMode;
import li.strolch.utils.collections.DateRange;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@SuppressWarnings("nls")
public class AuditQueryTest {
public static final String PATH_RUNTIME = "target/" + AuditQueryTest.class.getSimpleName();
private static Date past;
private static Date earlier;
private static Date current;
private static Date later;
private static Date future;
protected static final Logger logger = LoggerFactory.getLogger(AuditQueryTest.class);
@BeforeClass
public static void beforeClass() throws SQLException {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2000, 1, 1);
past = cal.getTime();
cal.set(2000, 4, 1);
earlier = cal.getTime();
cal.set(2000, 6, 1);
current = cal.getTime();
cal.set(2000, 8, 1);
later = cal.getTime();
cal.set(2000, 11, 1);
future = cal.getTime();
}
private static Certificate login(StrolchAgent agent) {
PrivilegeHandler privilegeHandler = agent.getContainer().getPrivilegeHandler();
return privilegeHandler.authenticate("test", "test".toCharArray());
}
@Test
public void shouldQueryTypeAndDateRange() throws Exception {
try {
RuntimeMock.runInStrolch(PATH_RUNTIME, PATH_REALM_CONTAINER, agent -> {
AuditVisitor<Audit> visitor = new NoStrategyAuditVisitor();
AuditQuery<Audit> query = new AuditQuery<>(visitor, Tags.AUDIT,
new DateRange().from(earlier, true).to(later, true));
performQuery(agent, query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(current, true).to(current, true));
performQuery(agent, query, Arrays.asList(1L, 3L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(current, true));
performQuery(agent, query, Arrays.asList(1L, 2L, 3L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().to(current, true));
performQuery(agent, query, Arrays.asList(0L, 1L, 3L, 4L));
query = new AuditQuery<>(visitor, Tags.RESOURCE, new DateRange().from(past, true).to(future, true));
performQuery(agent, query, Arrays.<Long>asList());
});
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
}
}
@Test
public void shouldQueryAudits() throws Exception {
try {
RuntimeMock.runInStrolch(PATH_RUNTIME, PATH_REALM_CONTAINER, agent -> {
AuditVisitor<Audit> visitor = new NoStrategyAuditVisitor();
AuditQuery<Audit> query = new AuditQuery<>(visitor, Tags.AUDIT,
new DateRange().from(past, true).to(future, true));
query.action().accessTypes(AccessType.CREATE, AccessType.READ);
performQuery(agent, query, Arrays.asList(0L, 1L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.action().accessTypes(AccessType.CREATE);
performQuery(agent, query, Arrays.asList(0L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.action().accessTypes(AccessType.CREATE, AccessType.READ)
.actions(StringMatchMode.EQUALS_CASE_SENSITIVE, "create", "read");
performQuery(agent, query, Arrays.asList(0L, 1L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.action().accessTypes(AccessType.CREATE, AccessType.READ)
.actions(StringMatchMode.EQUALS_CASE_SENSITIVE, "read");
performQuery(agent, query, Arrays.asList(1L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.element().elementAccessed(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "crea");
performQuery(agent, query, Arrays.asList(0L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.element().elementAccessed(StringMatchMode.CONTAINS_CASE_SENSITIVE, "crea");
performQuery(agent, query, Arrays.<Long>asList());
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.element().elementAccessed(StringMatchMode.EQUALS_CASE_INSENSITIVE, "create");
performQuery(agent, query, Arrays.asList(0L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier");
performQuery(agent, query, Arrays.asList(0L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier", "later");
performQuery(agent, query, Arrays.asList(0L, 2L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier")
.firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn");
performQuery(agent, query, Arrays.asList(0L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier")
.firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn")
.lastnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "kennedy");
performQuery(agent, query, Arrays.asList(0L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.identity().firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn")
.lastnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "kennedy");
performQuery(agent, query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Foo");
performQuery(agent, query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Bar");
performQuery(agent, query, Arrays.asList());
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
query.limit(1).element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Foo");
performQuery(agent, query, Arrays.asList(2L));
});
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
}
}
private void performQuery(StrolchAgent agent, AuditQuery<Audit> query, List<Long> expected) throws SQLException {
Certificate certificate = login(agent);
try (StrolchTransaction tx = agent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
.openTx(certificate, "test", false)) {
tx.setSuppressAudits(true);
tx.getAuditTrail().addAll(tx, getAudits());
List<Audit> result = tx.doQuery(query);
Set<Long> ids = new HashSet<>();
for (Audit audit : result) {
ids.add(audit.getId());
}
assertEquals(new HashSet<>(expected), new HashSet<>(ids));
}
}
private static List<Audit> getAudits() {
List<Audit> audits = new ArrayList<>();
int i = 0;
Audit randomAudit;
randomAudit = ModelGenerator.randomAudit();
randomAudit.setId(i++);
randomAudit.setUsername("earlier");
randomAudit.setDate(earlier);
randomAudit.setAccessType(AccessType.CREATE);
randomAudit.setAction("create");
randomAudit.setElementAccessed(randomAudit.getAccessType().name());
audits.add(randomAudit);
randomAudit = ModelGenerator.randomAudit();
randomAudit.setId(i++);
randomAudit.setDate(current);
randomAudit.setUsername("current");
randomAudit.setAccessType(AccessType.READ);
randomAudit.setAction("read");
randomAudit.setElementAccessed(randomAudit.getAccessType().name());
audits.add(randomAudit);
randomAudit = ModelGenerator.randomAudit();
randomAudit.setId(i++);
randomAudit.setDate(later);
randomAudit.setUsername("later");
randomAudit.setAccessType(AccessType.UPDATE);
randomAudit.setAction("update");
randomAudit.setElementAccessed(randomAudit.getAccessType().name());
audits.add(randomAudit);
randomAudit = ModelGenerator.randomAudit();
randomAudit.setId(i++);
randomAudit.setDate(current);
randomAudit.setUsername("current");
randomAudit.setAccessType(AccessType.DELETE);
randomAudit.setAction("delete");
randomAudit.setElementAccessed(randomAudit.getAccessType().name());
audits.add(randomAudit);
randomAudit = ModelGenerator.randomAudit();
randomAudit.setId(i++);
randomAudit.setDate(current);
randomAudit.setUsername("current");
randomAudit.setAccessType(AccessType.CREATE);
randomAudit.setAction("create");
randomAudit.setElementAccessed(randomAudit.getAccessType().name());
audits.add(randomAudit);
return audits;
}
}

Some files were not shown because too many files have changed in this diff Show More