Skip to content
Snippets Groups Projects
Commit 3ec010e7 authored by cramakri's avatar cramakri
Browse files

LMS-1544 Added collection predicate to more efficiently check a collection.

SVN: 16134
parent b95a5b74
No related branches found
No related tags found
No related merge requests found
/*
* 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment