From 3ec010e7247ba68ba08bbd2025cc78013c5b4dde Mon Sep 17 00:00:00 2001 From: cramakri <cramakri> Date: Thu, 27 May 2010 07:39:10 +0000 Subject: [PATCH] LMS-1544 Added collection predicate to more efficiently check a collection. SVN: 16134 --- ...pleOwnerIdentifierCollectionPredicate.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/predicate/SampleOwnerIdentifierCollectionPredicate.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/predicate/SampleOwnerIdentifierCollectionPredicate.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/predicate/SampleOwnerIdentifierCollectionPredicate.java new file mode 100644 index 00000000000..d6ecafe6625 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/predicate/SampleOwnerIdentifierCollectionPredicate.java @@ -0,0 +1,95 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.openbis.generic.shared.authorization.predicate; + +import java.util.List; + +import ch.systemsx.cisd.common.exceptions.Status; +import ch.systemsx.cisd.openbis.generic.shared.authorization.IAuthorizationDataProvider; +import ch.systemsx.cisd.openbis.generic.shared.authorization.RoleWithIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.ShouldFlattenCollections; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleOwnerIdentifier; + +/** + * An <code>IPredicate</code> implementation based on {@link SampleOwnerIdentifier}. + * + * @author Chandrasekhar Ramakrishnan + */ +@ShouldFlattenCollections(value = false) +public final class SampleOwnerIdentifierCollectionPredicate extends + AbstractPredicate<List<SampleOwnerIdentifier>> +{ + private final SpaceIdentifierPredicate spacePredicate; + + private final DatabaseInstanceIdentifierPredicate databaseInstanceIdentifierPredicate; + + public SampleOwnerIdentifierCollectionPredicate() + { + this(true); + } + + public SampleOwnerIdentifierCollectionPredicate(boolean isReadAccess) + { + spacePredicate = new SpaceIdentifierPredicate(); + databaseInstanceIdentifierPredicate = new DatabaseInstanceIdentifierPredicate(isReadAccess); + } + + // + // AbstractPredicate + // + + public final void init(IAuthorizationDataProvider provider) + { + spacePredicate.init(provider); + databaseInstanceIdentifierPredicate.init(provider); + } + + @Override + public final String getCandidateDescription() + { + return "sample identifier"; + } + + @Override + final Status doEvaluation(final PersonPE person, final List<RoleWithIdentifier> allowedRoles, + final List<SampleOwnerIdentifier> values) + { + for (SampleOwnerIdentifier value : values) + { + if (value.isDatabaseInstanceLevel()) + { + Status result = + databaseInstanceIdentifierPredicate.doEvaluation(person, allowedRoles, + value.getDatabaseInstanceLevel()); + if (Status.OK != result) + { + return result; + } + } else + { + Status result = + spacePredicate.doEvaluation(person, allowedRoles, value.getSpaceLevel()); + if (Status.OK != result) + { + return result; + } + } + } + return Status.OK; + } +} -- GitLab