diff --git a/pom.xml b/pom.xml index a07b6b593..e34d5eefe 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,10 @@ ch.eitchnet ch.eitchnet.utils + + ch.eitchnet + ch.eitchnet.privilege + diff --git a/src/main/java/li/strolch/model/audit/AuditQuery.java b/src/main/java/li/strolch/model/audit/AuditQuery.java index d752c0c3d..840d8f785 100644 --- a/src/main/java/li/strolch/model/audit/AuditQuery.java +++ b/src/main/java/li/strolch/model/audit/AuditQuery.java @@ -18,13 +18,14 @@ package li.strolch.model.audit; import java.util.ArrayList; import java.util.List; +import li.strolch.model.query.StrolchQuery; import ch.eitchnet.utils.collections.DateRange; import ch.eitchnet.utils.dbc.DBC; /** * @author Robert von Burg */ -public class AuditQuery { +public class AuditQuery implements StrolchQuery { private String elementTypeSelection; private List selections; @@ -71,4 +72,20 @@ public class AuditQuery { selection.accept(visitor); } } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() + */ + @Override + public String getPrivilegeName() { + return StrolchQuery.class.getName(); + } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() + */ + @Override + public Object getPrivilegeValue() { + return getClass().getName(); + } } diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index 68ff20094..b7d3347c9 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -28,7 +28,7 @@ import li.strolch.model.parameter.Parameter; * * @author Robert von Burg */ -public class OrderQuery extends StrolchQuery { +public class OrderQuery extends StrolchElementQuery { public OrderQuery(Navigation navigation) { super(navigation); diff --git a/src/main/java/li/strolch/model/query/Query.java b/src/main/java/li/strolch/model/query/Query.java deleted file mode 100644 index 1f2b7057c..000000000 --- a/src/main/java/li/strolch/model/query/Query.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2013 Robert von Burg - * - * 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 - * - */ -public interface Query { - - public void visit(T queryVisitor); -} diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java index dafe44eab..900d2659a 100644 --- a/src/main/java/li/strolch/model/query/ResourceQuery.java +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -28,7 +28,7 @@ import li.strolch.model.parameter.Parameter; * * @author Robert von Burg */ -public class ResourceQuery extends StrolchQuery { +public class ResourceQuery extends StrolchElementQuery { /** * @param navigation diff --git a/src/main/java/li/strolch/model/query/StrolchElementQuery.java b/src/main/java/li/strolch/model/query/StrolchElementQuery.java new file mode 100644 index 000000000..78c429815 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchElementQuery.java @@ -0,0 +1,103 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 ch.eitchnet.utils.dbc.DBC; + +/** + * @author Robert von Burg + */ +public abstract class StrolchElementQuery implements StrolchQuery { + + private Navigation navigation; + private Selection selection; + + public StrolchElementQuery(Navigation navigation) { + this.navigation = navigation; + } + + public boolean hasNavigation() { + return this.navigation != null; + } + + public boolean hasSelection() { + return this.selection != null && this.selection.hasSelection(); + } + + public Selection getSelection() { + return this.selection; + } + + public StrolchElementQuery 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 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 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 ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() + */ + @Override + public String getPrivilegeName() { + return StrolchQuery.class.getName(); + } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() + */ + @Override + public Object getPrivilegeValue() { + return getClass().getName(); + } +} diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index 640c04f4d..018e3b9e4 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -15,73 +15,12 @@ */ package li.strolch.model.query; -import ch.eitchnet.utils.dbc.DBC; +import ch.eitchnet.privilege.model.Restrictable; /** * @author Robert von Burg */ -public abstract class StrolchQuery { +public interface StrolchQuery extends Restrictable { - private Navigation navigation; - private Selection selection; - - public StrolchQuery(Navigation navigation) { - this.navigation = navigation; - } - - public boolean hasNavigation() { - return this.navigation != null; - } - - public boolean hasSelection() { - return this.selection != null && this.selection.hasSelection(); - } - - public Selection getSelection() { - return this.selection; - } - - public StrolchQuery 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 StrolchQuery 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 StrolchQuery 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); - } + // marker interface }